QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#683142 | #9529. Farm Management | potential# | WA | 1ms | 5756kb | C++20 | 1.2kb | 2024-10-27 19:01:52 | 2024-10-27 19:01:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
typedef pair<int,int> pii;
const int N=3e5+10;
struct node{
int w,l,r;
}a[N];
int sum[N];
int ss[N];
void solve(){
int n,m;
cin>>n>>m;
int now=0;
int nw=0;
for(int i=1;i<=n;i++) {
cin>>a[i].w>>a[i].l>>a[i].r;
now+=a[i].l;
nw+=a[i].l*a[i].w;
}
sort(a+1,a+1+n,[&](node a,node b){
return a.w>b.w;
});
for(int i=1;i<=n;i++){
sum[i]=sum[i-1]+a[i].r-a[i].l;
ss[i]=ss[i-1]+(a[i].r-a[i].l)*a[i].w;
}
// cout<<"now= "<<now<<"\n";
// cout<<"nw= "<<nw<<"\n";
// for(int i=1;i<=n;i++){
// cout<<a[i].w<<" "<<a[i].l<<" "<<a[i].r<<"\n";
// }
int ans=0;
for(int i=1;i<=n;i++){
int pos=upper_bound(sum,sum+1+i,a[i].l+m-now)-sum;
ans=max(ans,nw+ss[pos-1]-(a[i].l)*a[i].w+a[pos].w*(m-now-sum[pos-1]+a[i].l));
// cout<<ans<<" "<<pos<<" "<<"\n";
}
cout<<ans<<"\n";
}
signed main(){
IOS
int T=1;
// cin>>T;
while(T--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5668kb
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: 5756kb
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: 1ms
memory: 5692kb
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:
21525595
result:
wrong answer 1st lines differ - expected: '22000255', found: '21525595'