QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#689114 | #9529. Farm Management | zny780624# | WA | 1ms | 5668kb | C++20 | 1.9kb | 2024-10-30 15:23:57 | 2024-10-30 15:23:57 |
Judging History
answer
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<bitset>
#include<cstring>
#include<queue>
#define fi first
#define se second
using namespace std;
using ll=long long;
typedef pair<int,int>PII;
const int N=1e5+10;
struct node{
ll w,l,r;
}a[N];
int n;
ll m;
ll suf[N];
ll suf_cost[N];
void silverwolf(){
cin>>n>>m;
ll ans=0;
ll res=0,costm=m;
for(int i=1;i<=n;i++){
ll w,l,r;
cin>>w>>l>>r;
a[i]={w,l,r};
res+=w*l;
costm-=l;
}
sort(a+1,a+n+1,[](node x,node y){
return x.w<y.w;
});
for(int i=n;i>=1;i--){
suf[i]=suf[i+1]+a[i].r-a[i].l;
suf_cost[i]=suf_cost[i+1]+a[i].w*(a[i].r-a[i].l);
}
for(int i=1;i<=n;i++){
auto [w,l,r]=a[i];
//cout<<w<<' '<<l<<' '<<r<<'\n';
}
//for(int i=1;i<=n;i++)cout<<suf[i]<<' ';cout<<'\n';
// for(int i=1;i<=n;i++)cout<<suf_cost[i]<<' ';cout<<'\n';
//cout<<'\n';
for(int i=1;i<=n;i++){
//ban
auto [w,l,r]=a[i];
res-=w*l;
costm+=l;
//cout<<i<<' '<<costm<<'\n';
if(suf[i+1]<=costm){
ll tmp=res+suf_cost[i+1]+(costm-suf[i+1])*w;
ans=max(ans,tmp);
res+=w*l;
costm-=l;
//cout<<i<<' '<<tmp<<'\n';
//cout<<i<<' '<<r<<' '<<tmp<<'\n';
continue;
}
int L=i+1,R=n;
while(L<R){
int mid=L+R>>1;
if(suf[mid]<=costm)R=mid;
else L=mid+1;
}
ll tmp=res+suf_cost[R]+(costm-suf[R])*(a[R-1].w);
// cout<<i<<' '<<R<<' '<<tmp<<'\n';
ans=max(ans,tmp);
res+=w*l;
costm-=l;
}
cout<<ans<<'\n';
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
//int T;cin>>T;while(T--)
silverwolf();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3708kb
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: 5668kb
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'