QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#683664 | #9529. Farm Management | ivyoruska# | WA | 1ms | 3604kb | C++20 | 2.3kb | 2024-10-27 22:36:26 | 2024-10-27 22:36:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
struct crop {
i64 w;
i64 l, r;
bool operator<(const crop& z) const {
return w > z.w;
}
};
i64 ret;
void solve() {
int n;
i64 m;
cin >> n >> m;
ret = 0;
vector<crop> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].w >> a[i].l >> a[i].r;
// cerr << i << '\n';
}
sort(a.begin(), a.end());
vector<i64> num(n, 0); // 各个作物取了多少个
i64 res = 0;
i64 nums = 0; // 总量
for (int i = 0; i < n; i++) {
res += a[i].l * a[i].w;
num[i] = a[i].l;
nums += num[i];
// cerr << res << '\n';
}
ret = max(ret, res + (m - nums) * a[0].w);
for (int i = 0; i < n; i++) {
if (nums + a[i].r - a[i].l < m) {
nums += a[i].r - a[i].l;
num[i] = a[i].r;
res += (a[i].r - a[i].l) * a[i].w;
} else {
num[i] += m - nums;
res += (m - nums) * a[i].w;
nums = m;
break;
}
}
// cerr << ret << '\n';
vector<i64> prefix;
vector<i64> prefixw;
prefix.emplace_back(a[0].r - num[0]);
prefixw.emplace_back(prefix[0] * a[0].w);
for (int i = 1; i < n; i++) {
prefix.emplace_back(prefix[i - 1] + (a[i].r - num[i]));
prefixw.emplace_back(prefixw[i - 1] + (a[i].r - num[i]) * a[i].w);
i64 tnum = num[i];
int p = lower_bound(prefix.begin(), prefix.end(), tnum) - prefix.begin();
cerr << i << ' ' << p << '\n';
if (p >= i) {
ret = max(ret, res + prefixw[i - 1] - prefix[i - 1] * a[i].w);
// cerr << res + prefixw[i - 1] - prefix[i - 1] * a[i].w << '\n';
} else {
if (prefix[p] > tnum) p--;
ret = max(ret, res + prefixw[p] + a[p + 1].w * (tnum - prefix[p]) - tnum * a[i].w);
}
// cerr << i << ' ' << ret << '\n';
}
/*
for (i64 x : prefix) cerr << x << ' ';
cerr << '\n';
for (i64 x : prefixw) cerr << x << ' ';
cerr << '\n';
*/
cout << ret << '\n';
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
int _ = 1;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3552kb
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: 3604kb
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'