QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#800800 | #9529. Farm Management | lwj1239 | WA | 1ms | 7680kb | C++11 | 1.6kb | 2024-12-06 15:45:56 | 2024-12-06 15:45:58 |
Judging History
answer
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 10;
struct node {
int w;
int l;
int r;
}a[N];
int sum[N];
int cnt[N];
int n;
int m;
int get(int x, int r) {
int l = 1;
int ans = 0;
while (l <= r) {
int mid = (l + r) / 2;
if (cnt[mid] <= x) {
ans = mid;
l = mid + 1;
}
else r = mid - 1;
}
return ans;
}
void solve() {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].l >> a[i].r;
}
sort(a + 1, a + 1 + n, [](node x, node y) {
return x.w > y.w;
});
int tot = 0, res = 0;
for (int i = 1; i <= n; i++) {
tot += a[i].w * a[i].l;
m -= a[i].l;
sum[i] = (a[i].r - a[i].l) * a[i].w;
cnt[i] = a[i].r - a[i].l;
}
for (int i = 2; i <= n; i++) {
sum[i] += sum[i - 1];
cnt[i] += cnt[i - 1];
}
for (int i = 1; i <= n; i++) {
int cur = m + a[i].l;
int p = get(cur, i - 1);//因为是完全不种植第i种植物,所以我们只能看第i种前面的,因为后面的一定不优
cur -= cnt[p];
int t = tot - a[i].l * a[i].w + sum[p];
int j = i + 1;
while (j <= n && cur) {
t += min(cur, a[j].r - a[j].l) * a[j].w;
cur -= min(cur, a[j].r - a[j].l);
j ++;
}
// cout << "p = " << p << ' ' << "cur = " << cur << " " << "t = " << t << endl;
res = max(res, t);
}
cout << res << endl;
}
signed main() {
solve();
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7680kb
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: 7680kb
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'