QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#693631#9529. Farm ManagementZycK#WA 1ms5680kbC++141.6kb2024-10-31 16:29:472024-10-31 16:29:47

Judging History

你现在查看的是最新测评结果

  • [2024-10-31 16:29:47]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5680kb
  • [2024-10-31 16:29:47]
  • 提交

answer

#include <bits/stdc++.h>
#define int ll
#define For(i, l, r) for (int i=l; i<=r; ++i)
using namespace std;
typedef long long ll;
template <typename T>
inline void read(T &x) {
	char c = getchar(); int w = 1; x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}

const int N = 100010;
int n, m, use[N], sum[N], Up[N], Pre[N];
struct node {
	int w, l, r;
	inline bool operator < (const node &rhs) const {
		return w < rhs.w;
	}
} a[N];
signed main() {
	read(n); read(m);
	ll m1 = m;
	For(i, 1, n) {
		read(a[i].w); read(a[i].l); read(a[i].r);
		m1 -= a[i].l;
	}
	std :: sort(a + 1, a + n + 1);
	ll Ans = 0;
	For(i, 1, n) {
		Ans = Ans + a[i].w * a[i].l;
		use[i] = a[i].l;
	}
	Ans += (m1) * a[n].w;
	int Id = -1;
	sum[n+1] = 0;
	Up[n+1] = 0;
	for (int i=n; i>=1; --i) {
		if (a[i].r-a[i].l <= m1) {
			m1 -= a[i].r-a[i].l;
			use[i] = a[i].r;
		}
		else {
			use[i] += m1; m1 = 0;
		}
		if (use[i] < a[i].r && Id == -1) {
			Id = i;
		}
		sum[i] = sum[i+1] + a[i].r-use[i];
		Up[i] = Up[i+1] + a[i].r * a[i].w;
	}
	Pre[0] = 0;
	For(i, 1, n) {
		Pre[i] = Pre[i-1] + use[i] * a[i].w;
	}
	for (int i=1; i<Id; ++i) {
		int l = i+1, r = Id;
		while (l <= r) {
			int mid = l+r >> 1;
			if (sum[mid] >= a[i].l) l = mid+1;
			else r = mid-1;
		}
		if (r == i) r = i+1;
		ll now = 0;
		if (sum[r] <= a[i].l) {
			now = Up[r] + Pre[r-1] - sum[r] * a[i].w;
		}
		else {
			now = Up[r+1] + Pre[r-1] + (a[i].l-sum[r+1]) * a[r].w - a[i].l * a[i].w;
		}
		Ans = max(Ans, now);
	}
	cout << Ans << endl;
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5680kb

input:

5 17
2 3 4
6 1 5
8 2 4
4 3 3
7 5 5

output:

109

result:

ok single line: '109'

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 5616kb

input:

12 62
503792 9 10
607358 1 3
600501 10 10
33249 4 4
774438 6 6
197692 3 6
495807 8 8
790225 5 9
77272 3 8
494819 4 9
894779 3 9
306279 5 6

output:

34859047

result:

wrong answer 1st lines differ - expected: '35204500', found: '34859047'