QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#743842 | #9529. Farm Management | susanzhishen# | WA | 1ms | 5644kb | C++20 | 1.5kb | 2024-11-13 20:09:32 | 2024-11-13 20:09:36 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int N = 1e5 + 100;
int n;
LL m;
struct DATA {
LL w, l, r;
} d[N];
bool cmp(DATA &a, DATA &b) {
return a.w > b.w;
}
LL pre[N], prew[N];
LL calc(int x, LL rm) {
if(pre[x - 1] <= rm)
return prew[x - 1] + d[x].w * (rm - pre[x - 1]);
int l = 1, r = x - 1;
while(l < r) {
int md = (l + r) / 2;
if(pre[md] <= rm) r = md - 1;
else l = md + 1;
}
return prew[r] + (rm - pre[r]) * d[l].w;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> m;
LL sum = 0;
for(int i = 1; i <= n; ++i) {
cin >> d[i].w >> d[i].l >> d[i].r;
m -= d[i].l;
sum += d[i].w * d[i].l;
}
sort(d + 1, d + 1 + n, cmp);
for(int i = 1; i <= n; ++i) {
pre[i] = pre[i - 1] + d[i].r - d[i].l;
prew[i] = prew[i - 1] + (d[i].r - d[i].l) * d[i].w;
}
// for(int i = 1; i <= n; ++i)
// cerr << pre[i] << ' ' << prew[i] << endl;
// return 0;
// cerr << sum << ' ' << m << endl;
LL ans = 0;
for(int i = 1; i <= n; ++i) {
ans = max(ans, sum - d[i].l * d[i].w + calc(i, m + d[i].l));
// cerr << m + d[i].l << ' ' << calc(i, m + d[i].l) << ' ' << sum - d[i].l * d[i].w + calc(i, m + d[i].l) << endl;
}
cout << ans << endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3628kb
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: 5644kb
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:
43038513
result:
wrong answer 1st lines differ - expected: '35204500', found: '43038513'