QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#784242#9529. Farm ManagementFire_RakuWA 1ms5752kbC++141.3kb2024-11-26 14:15:382024-11-26 14:15:48

Judging History

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

  • [2024-11-26 14:15:48]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5752kb
  • [2024-11-26 14:15:38]
  • 提交

answer

#include <bits/stdc++.h>
#define pb push_back
#define pii std::pair<int, int>
#define fi first
#define se second
#define i64 long long
const i64 iinf = 0x3f3f3f3f, linf = 0x3f3f3f3f3f3f3f3f;
const int N = 3e5 + 10;
i64 t, n, m;
struct node {
	i64 w, l, r;
} a[N];
i64 c[N], d[N];
void fake_main() {
	i64 ans1 = 0, ans2 = 0;
	std::cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		std::cin >> a[i].w >> a[i].l >> a[i].r;
	}
	std::sort(a + 1, a + n + 1, [](node a, node b) {
		return a.w > b.w;
	});
	i64 val = 0, sum = 0, ans = 0;
	for(int i = 1; i <= n; i++) {
		val += a[i].l * a[i].w;
		c[i] = a[i].r - a[i].l;
		c[i] += c[i - 1];
		d[i] = (a[i].r - a[i].l) * a[i].w;
		d[i] += d[i - 1];
		sum += a[i].l;
	}
	for(int i = 1; i <= n; i++) {
		int l = 1, r = i - 1, ret = -1;
		while(l <= r) {
			int mid = (l + r) >> 1;
			if(c[mid] >= m - sum + a[i].l) ret = mid, r = mid - 1;
			else l = mid + 1;
		}
		if(ret != -1) {
			ans = std::max(ans, val - a[i].l * a[i].w + d[ret - 1] + (m - sum + a[i].l - c[ret - 1]) * a[ret].w);
		} else {
			ans = std::max(ans, val - a[i].l * a[i].w + d[i - 1] + (m - sum + a[i].l - c[i - 1]) * a[i].w);
		}
	}
	std::cout << ans << "\n";
}
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(nullptr);
	
	std::cin >> t;
	while(t--) fake_main();
	
	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5752kb

input:

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

output:

0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '109', found: '0'