QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#701629 | #9529. Farm Management | Magical_Kingdom# | RE | 0ms | 3648kb | C++17 | 1.4kb | 2024-11-02 14:27:38 | 2024-11-02 14:27:39 |
Judging History
answer
#include <algorithm>
#include <iostream>
using namespace std;
struct zz {
long long l, r, w;
} zw[100050];
int cmp(zz a, zz b) {
return a.w < b.w;
}
int main() {
long long n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> zw[i].w >> zw[i].l >> zw[i].r;
}
long long ans = 0;
sort(zw + 1, zw + 1 + n, cmp);
long long tt = m;
for (int i = 1; i < n; i++) {
tt -= zw[i].l;
ans += zw[i].w * zw[i].l;
}
long long zc = ans + zw[n].w * zw[n].l;
long long zg = 0;
zg = tt - zw[n].l;
ans += zw[n].w * tt;
int i = 1, j = n;
long long sy = zw[j].l;
long long ans2 = 0;
while (i < j) {
zg += zw[i].l;
zc -= zw[i].l * zw[i].w;
while (i <= j && zg > 0) {
if (zg >= zw[j].r - sy) {
zg -= zw[j].r - sy;
zc += (zw[j].r - sy) * zw[j].w;
j--;
sy = zw[j].l;
ans2 = max(ans2, zc);
} else {
zc += zg * zw[j].w;
sy += zg;
zg = 0;
ans2 = max(ans2, zc);
}
}
zg -= zw[i].l;
zc += zw[i].l * zw[i].w;
int ff = i + 1;
while (zw[ff].l < zw[i].l)
ff++;
i = ff;
}
cout << max(ans, ans2);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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
Runtime Error
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