QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#685514 | #9529. Farm Management | PHarr | WA | 0ms | 3808kb | C++20 | 1.1kb | 2024-10-28 19:48:25 | 2024-10-28 19:48:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i32 = int32_t;
using i64 = long long;
#define int i64
using vi = vector<int>;
i32 main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<array<int,3>> c(n + 1);
for(int i = 1; i <= n; i ++) {
int w, l, r;
cin >> w >> l >> r;
c[i] = {w, l, r - l};
}
ranges::sort(c);
int sum = 0, used = 0;
for(int i = 1; i <= n; i ++) {
auto [wi, li, ri] = c[i];
sum += li * wi, used += li;
}
vi suf(n + 2), suf_used(n + 2);
for(int i = n; i >= 1; i --) {
suf[i] = suf[i + 1] + c[i][0] * c[i][2];
suf_used[i] = suf_used[i + 1] + c[i][2];
}
int res = 0;
for(int i = 1; i <= n; i ++) {
int now_sum = sum - c[i][1] * c[i][0];
int now_can = m - (used - c[i][1]);
int l = i + 1, r = n + 1, it = -1;
while(l <= r) {
int mid = (l + r) / 2;
if(suf_used[mid] <= now_can) it = mid, r = mid - 1;
else l = mid + 1;
}
now_sum += suf[it];
now_can -= suf_used[it];
it --;
now_can += now_can * c[it][0];
res = max(res, now_sum);
}
cout << res;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
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: 0ms
memory: 3536kb
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'