QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#689614 | #9529. Farm Management | KeeperHihi | WA | 0ms | 3528kb | C++20 | 2.1kb | 2024-10-30 17:58:25 | 2024-10-30 17:58:28 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
void solve() {
int n, m;
cin >> n >> m;
vector<tuple<i64, i64, i64>> a(n + 1);
i64 tot = 0;
i64 cnt = 0;
for (int i = 1; i <= n; i++) {
i64 x, y, z;
cin >> x >> y >> z;
a.emplace_back(x, y, z);
cnt += y;
tot += x * y;
}
i64 ans = tot;
sort(a.begin() + 1, a.end(), greater<tuple<i64, i64, i64>>());
vector<i64> pre(n + 1), precnt(n + 1);
for (int i = 1; i <= n; i++) {
auto [w, l, r] = a[i];
pre[i] = pre[i - 1] + w * (r - l);
precnt[i] = precnt[i - 1] + r - l;
}
for (int i = 1, c = 0; i <= n; i++) {
auto [w, l, r] = a[i];
if (c + r - l <= m) {
c += r - l;
ans += (r - l) * w;
} else {
ans += (m - c) * w;
c = m;
}
}
for (int i = 1; i <= n; i++) {
auto [w, l, r] = a[i];
ans = max(ans, tot + (m - cnt) * w);
i64 pos = tot - w * l;
i64 has = m - (cnt - l);
auto cal = [&](int x) -> pair<i64, i64> {
i64 sum = pre[x];
if (x >= i) sum -= w * (r - l);
i64 c = precnt[x];
if (x >= i) c -= r - l;
return {c, sum};
};
int L = 0, R = n;
while (L < R) {
int mid = L + R + 1 >> 1;
auto [ned, sum] = cal(mid);
if (ned > has) {
R = mid - 1;
} else {
L = mid;
}
}
auto [cost, sum] = cal(L);
pos += sum;
assert(L + 1 != i);
if (L + 1 <= n) {
auto [ww, ll, rr] = a[L + 1];
pos += (has - cost) * ww;
}
ans = max(ans, pos);
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3528kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
117
result:
wrong answer 1st lines differ - expected: '109', found: '117'