QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#688271 | #9529. Farm Management | xinlengweishang | WA | 1ms | 6012kb | C++20 | 1.1kb | 2024-10-30 02:02:14 | 2024-10-30 02:02:15 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000010
using namespace std;
struct node{
ll w;
ll l,r;
}a[maxn];
ll suml[maxn],sumr[maxn],sumvall[maxn],sumvalr[maxn];
ll n,m;
bool cmp(node a,node b){
return a.w<b.w;
}
ll cal(ll x){
if(sumr[n]-sumr[x]+suml[x-1]<=m){
return sumvalr[n]-sumvalr[x]+sumvall[x-1]+(m-(sumr[n]-sumr[x]+suml[x-1]))*a[x].w;
}
else{
ll l=x,r=n+1;
while(l+1!=r){
ll mid=(l+r)>>1;
if(suml[mid]+sumr[n]-sumr[mid]-a[x].l>=m) r=mid;
else l=mid;
}
return sumvall[l-1]-a[x].l*a[x].w+sumvalr[n]-sumvalr[l]+(m-(suml[l-1]+sumr[n]-sumr[l]))*a[x].w;
}
}
void slove(){
scanf("%lld%lld",&n,&m);
for(int i=1;i<=n;i++){
scanf("%lld%lld%lld",&a[i].w,&a[i].l,&a[i].r);
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=n;i++){
suml[i]=suml[i-1]+a[i].l;
sumr[i]=sumr[i-1]+a[i].r;
sumvall[i]=sumvall[i-1]+a[i].l*a[i].w;
sumvalr[i]=sumvalr[i-1]+a[i].r*a[i].w;
}
ll ans=0;
for(int i=1;i<=n;i++){
ans=max(ans,cal(i));
}
printf("%lld",ans);
return ;
}
int main(){
int T=1;
// scanf("%d",&T);
while(T--) slove();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5960kb
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: 1ms
memory: 6012kb
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:
43874023
result:
wrong answer 1st lines differ - expected: '35204500', found: '43874023'