QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#747496 | #9529. Farm Management | SSHL | WA | 0ms | 3852kb | C++20 | 1.6kb | 2024-11-14 17:19:45 | 2024-11-14 17:19:48 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve()
{
ll n, m;
cin >> n >> m;
vector<pair<ll, pair<ll, ll>>> a(n+1);
ll t[n+1]={0},cnt=0;
for (int i = 1; i <= n; i++)
{
cin >> a[i].first >> a[i].second.first >> a[i].second.second;
cnt += a[i].second.second;
}
sort(a.begin()+1, a.end());
for(int i=1;i<=n;i++)
{
if(cnt-m>=a[i].second.second-a[i].second.first)
{
t[i]=a[i].second.first;
cnt-=a[i].second.second-a[i].second.first;
}else{
t[i]=a[i].second.second-cnt+m;
cnt=m;
}
}
ll d[n+2]={0},e[n+2]={0};
for(int i=n;i>=1;i--)
{
d[n-i+1]=d[n-i]-t[i]+a[i].second.second;
e[n-i+1]=e[n-i]+(-t[i]+a[i].second.second)*a[i].first;
}
// for(int i=1;i<=n;i++)
// {
// cout<<a[i].first<<' '<<a[i].second.first<<' '<<a[i].second.second<<' '<<t[i]<<' '<<d[i]<<' '<<e[i]<<'\n';
// }
ll a2=0;
for(int i=1;i<=n;i++)
{
ll l=0,r=n-i;
while(l+1<r)
{
ll mid=(l+r)/2;
if(d[mid]<t[i])
l=mid;
else r=mid;
}
a2=max(a2,e[l]+(t[i]-d[l])*a[n-l].first-t[i]*a[i].first);
// cout<<l<<' '<<r<<' '<<d[l]<<' '<<e[l]<<'\n';
}
// cout<<a2<<'\n';
for(int i=1;i<=n;i++)
{
a2+=t[i]*a[i].first;
}
cout<<a2;
}
int main()
{
ios::sync_with_stdio(false);
cin.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: 3588kb
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: 0ms
memory: 3852kb
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: -100
Wrong Answer
time: 0ms
memory: 3788kb
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:
17806486
result:
wrong answer 1st lines differ - expected: '22000255', found: '17806486'