QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#728688 | #9529. Farm Management | iokanux# | WA | 0ms | 3612kb | C++20 | 2.3kb | 2024-11-09 15:40:09 | 2024-11-09 15:40:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
struct Node {
int w, l, r;
int s1;
};
struct node {
int sum, cnt;
int pos;
};
void solve() {
int n, m;cin >> n >> m;
vector<Node>a(n + 1);
for (int i = 1;i <= n;i++) {
cin >> a[i].w >> a[i].l >> a[i].r;
a[i].s1 = a[i].w * a[i].l;
}
sort(a.begin() + 1, a.end(), [&](auto l, auto r) {
return l.w < r.w;
});
vector<int>pre(n + 10, 0), suf(n + 10, 0);
vector<int>presum(n + 10, 0), sufsum(n + 10, 0);
for (int i = 1;i <= n;i++) {
pre[i] = pre[i - 1] + a[i].l;
presum[i] = presum[i - 1] + a[i].l * a[i].w;
}
vector<pair<int, int>>oth;
for (int i = n;i >= 1;i--) {
if (a[i].r + pre[i - 1] + (suf[i + 1]) <= m) {
suf[i] = suf[i + 1] + a[i].r;
}
else {
int k = m - pre[i - 1] - suf[i + 1];
oth.push_back({ a[i].r - k,i });
suf[i] = suf[i + 1] + k;
}
sufsum[i] = sufsum[i + 1] + (suf[i] - suf[i + 1]) * a[i].w;
}
sort(oth.begin(),oth.end(),[&](auto l,auto r){
return l.second>r.second;
});
vector<node>oth2(oth.size() + 1);
for (int i = 0;i < oth.size();i++) {
oth2[i + 1].cnt = oth2[i].cnt + oth[i].first;
oth2[i + 1].sum = oth2[i].sum + a[oth[i].second].w * oth[i].first;
oth2[i + 1].pos = oth[i].second;
}
// sort(oth2.begin() + 1, oth2.end(), [&](auto l, auto r) {
// return l.sum < r.sum;
// });
int ans = 0;
for (int i = 1;i <= n;i++) {
int m1 = presum[i - 1];
int m2 = sufsum[i + 1];
int t = m - pre[i - 1] - suf[i + 1];
int l = 1, r = oth2.size() + 1;
while (l + 1 != r) {
int mid = l + r >> 1;
if (oth2[mid].cnt >= t && oth2[mid].pos >= i) r = mid;
else l = mid;
}
//cout << l << "\n";
//l=r;
int el = 0;
if (t - oth2[l].cnt >= 0) el = t - oth2[l].cnt;
ans = max(ans, m1 + m2 + oth2[l].sum + el * a[i].w);
}
cout << ans << "\n";
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
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: 3612kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
100852
result:
wrong answer 1st lines differ - expected: '109', found: '100852'