QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#717887 | #9529. Farm Management | Bicycle_23 | RE | 1ms | 5676kb | C++20 | 2.0kb | 2024-11-06 19:11:31 | 2024-11-06 19:11:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define frep(i,a,b) for(int i=a;i>=b;i--)
constexpr int maxn = 1e5 + 5;
int n, m;
struct node {
int w, l, r;
} a[maxn];
int la[maxn];
int mla[maxn];
int sum[maxn];
int msum[maxn];
bool cmp(node a, node b) {return a.w > b.w;}
int f(int l, int r, int x)
{
int t = a[x].r - la[x];
while (l < r)
{
int mid = (l + r) >> 1;
if (t > sum[mid] - la[x] * (x <= mid))
{
l = mid + 1;
}
else
{
r = mid;
}
}
int res = msum[l - 1] - mla[x] * (x < l) + max(0ll, t - (sum[l - 1] - la[x] * (x < l))) * a[l].w;
// cout << res << endl;
return res;
}
void solve()
{
cin >> n >> m;
rep(i, 1, n) {cin >> a[i].w >> a[i].l >> a[i].r;}
sort(a + 1, a + 1 + n, cmp);
int s = 0, st = 0, sst = 0;
rep(i, 1, n) {st += a[i].l; s += a[i].w * a[i].l; sst += a[i].r;}
int last = m - st;
int ans = s + last * a[1].w;
int idx = 1;
while (last >= (a[idx].r - a[idx].l)) {s += (a[idx].r - a[idx].l) * a[idx].w; last -= (a[idx].r - a[idx].l); idx++;}
rep(i, idx, n) {la[i] = a[i].r - a[i].l - last; mla[i] = la[i] * a[i].w; s += last * a[i].w; last = 0;}
rep(i, idx, n) {sum[i] = la[i] + sum[i - 1]; msum[i] = mla[i] + msum[i - 1];}
sum[n + 1] = 1e18;
msum[n + 1] = msum[n];
a[n + 1].w = 0;
// cout << endl;
// rep(i, 1, n) cout << a[i].w << " " << a[i].l << " " << a[i].r << endl;
// cout << idx << endl;
// cout << "la :";rep(i, idx, n) cout << la[i] << " "; cout << endl;
// rep(i, idx, n) cout << sum[i] << " "; cout << endl;
// cout << endl;
rep(i, idx, n)
{
int tmp = s - (a[i].r - la[i]) * a[i].w + f(idx, n + 1, i) + a[i].w * (m > sst - a[i].r ? (m - sst + a[i].r) : 0);
// cout << tmp << endl;
ans = max(ans, tmp);
}
cout << ans;
}
signed main()
{
cin.tie(0); cout.tie(0);
ios::sync_with_stdio(0);
int _ = 1;
// cin >> _;
while (_--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5676kb
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: 0
Accepted
time: 1ms
memory: 5612kb
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:
35204500
result:
ok single line: '35204500'
Test #3:
score: 0
Accepted
time: 0ms
memory: 5644kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
22000255
result:
ok single line: '22000255'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
13 20 526447 1 1 807398 2 2 4167 1 2 944031 2 2 830685 2 2 394251 1 2 505011 1 2 968848 1 1 58170 1 3 32504 1 1 792273 3 3 196120 1 2 714507 1 1
output:
12878768
result:
ok single line: '12878768'
Test #5:
score: -100
Runtime Error
input:
13 32 582584 1 3 335440 3 3 971984 1 2 864169 1 2 528515 1 1 382399 1 2 459855 1 2 406909 2 3 66780 2 3 885118 3 3 434844 1 2 93331 1 3 502509 1 3