QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#784242 | #9529. Farm Management | Fire_Raku | WA | 1ms | 5752kb | C++14 | 1.3kb | 2024-11-26 14:15:38 | 2024-11-26 14:15:48 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define pii std::pair<int, int>
#define fi first
#define se second
#define i64 long long
const i64 iinf = 0x3f3f3f3f, linf = 0x3f3f3f3f3f3f3f3f;
const int N = 3e5 + 10;
i64 t, n, m;
struct node {
i64 w, l, r;
} a[N];
i64 c[N], d[N];
void fake_main() {
i64 ans1 = 0, ans2 = 0;
std::cin >> n >> m;
for(int i = 1; i <= n; i++) {
std::cin >> a[i].w >> a[i].l >> a[i].r;
}
std::sort(a + 1, a + n + 1, [](node a, node b) {
return a.w > b.w;
});
i64 val = 0, sum = 0, ans = 0;
for(int i = 1; i <= n; i++) {
val += a[i].l * a[i].w;
c[i] = a[i].r - a[i].l;
c[i] += c[i - 1];
d[i] = (a[i].r - a[i].l) * a[i].w;
d[i] += d[i - 1];
sum += a[i].l;
}
for(int i = 1; i <= n; i++) {
int l = 1, r = i - 1, ret = -1;
while(l <= r) {
int mid = (l + r) >> 1;
if(c[mid] >= m - sum + a[i].l) ret = mid, r = mid - 1;
else l = mid + 1;
}
if(ret != -1) {
ans = std::max(ans, val - a[i].l * a[i].w + d[ret - 1] + (m - sum + a[i].l - c[ret - 1]) * a[ret].w);
} else {
ans = std::max(ans, val - a[i].l * a[i].w + d[i - 1] + (m - sum + a[i].l - c[i - 1]) * a[i].w);
}
}
std::cout << ans << "\n";
}
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cin >> t;
while(t--) fake_main();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5752kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
0 0 0 0 0
result:
wrong answer 1st lines differ - expected: '109', found: '0'