QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#692342#9529. Farm Managementreal_sigma_team#WA 0ms3844kbC++231.7kb2024-10-31 14:21:232024-10-31 14:21:27

Judging History

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

  • [2024-10-31 14:21:27]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3844kb
  • [2024-10-31 14:21:23]
  • 提交

answer

#include<bits/stdc++.h>

int main() {
	std::cin.tie(nullptr)->sync_with_stdio(false);

	int n;
	int64_t m;
	std::cin >> n >> m;
	std::vector<std::tuple<int64_t, int64_t, int64_t>> wei(n);
	int64_t cost = 0;
	int64_t sum_l = 0, sum_c = 0;
	for (auto& [w, l, r] : wei) std::cin >> w >> l >> r, sum_l += l, sum_c += l * w;
	std::sort(wei.begin(), wei.end(), std::greater<>());
	// for (auto [w, l, r] : wei) std::cout << w << ' ' << l << ' ' << r << std::endl;
	std::vector<int64_t> pref_delt(n + 1);
	std::vector<int64_t> pref_w(n + 1);
	for (int i = 0; i < n; ++i) {
		auto [w, l, r] = wei[i];
		pref_delt[i + 1] = pref_delt[i] + r - l;
		pref_w[i + 1] = pref_w[i] + (r - l) * w;
	}
	// for (auto i : pref_delt) std::cout << i << ' ';
	// std::cout << std::endl;
	int64_t ret = 0;
	for (int i = 0; i < n; ++i) {
		auto [w, l, r] = wei[i];
		sum_l -= l;
		sum_c -= w * l;
		int64_t need = m - sum_l;
		// std::cout << i << ' ' << need << std::endl;
		if (pref_delt.back() - (r - l) >= need && need >= 0) {
			if (need == 0) {
				ret = std::max(ret, sum_c);
			} else {
				int q = std::lower_bound(pref_delt.begin(), pref_delt.end(), need) - pref_delt.begin() - 1;
				if (q >= i) {
					q = std::lower_bound(pref_delt.begin(), pref_delt.end(), need + r - l) - pref_delt.begin() - 1;
				}
				int64_t delt = pref_delt[q];
				if (q >= i) delt -= r - l;
				int64_t ans = sum_c + pref_w[q] + (need - delt) * std::get<0>(wei[q]);
				if (q >= i) ans -= (r - l) * w;
				// std::cout << i << ' ' << ans << ' ' << sum_c << ' ' << q << ' ' << delt << std::endl;
				ret = std::max(ret, ans);
			}
		}
		sum_l += l;
		sum_c += w * l;
	}
	std::cout << ret;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3832kb

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: 0
Accepted
time: 0ms
memory: 3620kb

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:

35204500

result:

ok single line: '35204500'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3844kb

input:

15 32
835418 2 3
178262 1 3
527643 2 2
519710 1 1
774544 3 3
82312 1 1
808199 1 1
809396 1 3
255882 1 3
80467 1 3
874973 1 3
813965 1 2
198275 1 2
152356 1 3
802055 1 1

output:

17013157

result:

wrong answer 1st lines differ - expected: '22000255', found: '17013157'