QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#678574 | #9529. Farm Management | ucup-team4975# | WA | 0ms | 3804kb | C++23 | 1.8kb | 2024-10-26 15:24:23 | 2024-10-26 15:24:23 |
Judging History
answer
#include <bits/stdc++.h>
#define fir first
#define sec second
#define el '\n'
using namespace std;
using ll = long long;
using PII = pair<int, int>;
struct Data {
int w, l, r;
};
void solve()
{
int n, m;
cin >> n >> m;
int lft = m;
vector<Data> a(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i].w >> a[i].l >> a[i].r;
}
sort(next(a.begin()), a.end(), [&](Data x, Data y) {
if (x .w == y.w)
return x.l > y.l;
return x.w < y.w;
});
ll ans = 0;
for (int i = 1; i <= n; i++) {
ans += 1ll * a[i].w * a[i].l;
lft -= a[i].l;
}
// cout << ans << endl;
ll now = ans;
ans = ans + lft * (a[n].w);
// cout << ans << endl;
int cur = n, res = a[n].l, las = 0;
ll lassum = 0;
ll c = now;
for (int i = 1;i <= n; i++) {
if (a[i].l <= a[i - 1].l && i != 1)
continue;
int b = lft + a[i].l;
b = b - las;
las = b;
// cout << i << " " << b << endl;
while (cur >= 1 && b) {
int d = (a[cur].r - res);
d = min(d, b);
c += 1ll * d * a[cur].w;
res = res + d;
if (res == a[cur].r) {
cur--;
res = a[cur].l;
}
b -= d;
// cout << b << endl;
}
ans = max(ans, c - (1ll * a[i].w * a[i].l));
// cout << i << " " << c - (1ll * a[i].w * a[i].l) << endl;
// cout << "cur " << cur << endl;
// cout << "res " << res << endl;
}
cout << ans << el;
}
int 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: 100
Accepted
time: 0ms
memory: 3524kb
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: 0ms
memory: 3804kb
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:
39915777
result:
wrong answer 1st lines differ - expected: '35204500', found: '39915777'