QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#693399 | #9529. Farm Management | candy34# | WA | 0ms | 3688kb | C++20 | 1.4kb | 2024-10-31 16:04:57 | 2024-10-31 16:05:01 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define ph push_back
#define pp pop_back
using namespace std;
const int N=1e5+5;
int n,m;
int sumr[N],suml[N];
int wr[N],wl[N];
struct hhh
{
int w,l,r;
}a[N];
bool cmp(hhh x,hhh y)
{
return x.w>y.w;
}
bool check(int mid,int i)
{
return sumr[mid]+suml[n+1]-suml[mid]-a[i].l<=m;
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i].w>>a[i].l>>a[i].r;
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n+1;i++)
{
suml[i]=suml[i-1]+a[i].l,sumr[i]=sumr[i-1]+a[i].r;
wl[i]=wl[i-1]+a[i].l*a[i].w,wr[i]=wr[i-1]+a[i].r*a[i].w;
}
// suml[n+1]=suml[n]; sumr[n+1]=sumr[n];
int ans=0;
for(int i=1;i<=n;i++)
{
int res=0;
int t=sumr[i-1]+suml[n+1]-suml[i+1];
if(t<=m) res=wr[i-1]+wl[n+1]-wl[i+1]+(m-t)*a[i].w;
else
{
int l=1,r=i-1,id;
while(l<=r)
{
int mid=(l+r)>>1;
if(check(mid,i)) id=mid,l=mid+1;
else r=mid-1;
}
int num=sumr[id]+suml[n+1]-suml[i]+suml[i-1]-suml[id+1];
num=m-num;
res=wr[id]+wl[n+1]-wl[i]+wl[i-1]-wl[id+1]+num*a[id+1].w;
}
ans=max(ans,res);
}
cout<<ans<<endl;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3688kb
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: 3600kb
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:
35309054
result:
wrong answer 1st lines differ - expected: '35204500', found: '35309054'