QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#787938 | #9529. Farm Management | atriyatuoli | WA | 0ms | 3592kb | C++20 | 2.5kb | 2024-11-27 15:18:20 | 2024-11-27 15:18:20 |
Judging History
answer
#include <bits/stdc++.h>
#define MAX 0x3f3f3f3f
#define endl "\n"
using namespace std;
using ll = long long;
struct node{
ll w,l,r;
bool operator<(const node &other) const{
return w < other.w;
}
};
void solve(){
int n;
ll m;
cin>>n>>m;
vector <node> a(n+1);
for(int i=1;i<=n;i++){
cin>>a[i].w>>a[i].l>>a[i].r;
}
sort(a.begin()+1,a.end());
// for(int i=1;i<=n;i++){
// cerr << a[i].w << " " << a[i].l << " " << a[i].r << endl;
// }
vector <ll> prew(n+5);
vector <ll> prewl(n+5);
vector <ll> prel(n+5);
ll t=m;
for(int i=1;i<=n;i++){
prewl[i]=prewl[i-1]+a[i].l*a[i].w;
prew[i]=prew[i-1]+a[i].w;
prel[i]=prel[i-1]+a[i].l;
}
t-=prel[n];
vector <ll> sufw(n+5);
vector <ll> sufwl(n+5);
vector <ll> suflr(n+5);
vector <ll> sufwlr(n+5);
ll ans=prewl[n];
for(int i=n;i>=1;i--){
sufw[i]+=sufw[i+1]+a[i].w;
sufwl[i]+=sufwl[i+1]+a[i].w*a[i].l;
suflr[i]+=suflr[i+1]+(a[i].r-a[i].l);
sufwlr[i]+=sufwlr[i+1]+a[i].w*(a[i].r-a[i].l);
if(t>a[i].r-a[i].l){
t-=a[i].r-a[i].l;
ans+=(a[i].r-a[i].l)*a[i].w;
}
else{
ans+=t*a[i].w;
t=0;
}
}
// for(int i=1;i<=n;i++){
// cerr<<suflr[i]<<" ";
// }
// cerr<<endl;
for(int i=1;i<=n;i++){
ll res=prewl[n]-a[i].w*a[i].l;
ll x=m-prel[n];
x+=a[i].l;
//cerr<<x<<endl;
ll p = lower_bound(suflr.begin()+i+1, suflr.end(), x , greater<ll>()) - suflr.begin();
//cerr<<p<<endl;
x-=suflr[p];
res+=sufwlr[p];
res+=x*a[p-1].w;
//cerr<<p<<endl;
// for(int j=n;j>=1&&x>0;j--){//暴力
// if(j==i){
// res+=a[j].w*x;
// break;
// }
// if(x>a[j].r-a[j].l){
// res+=a[j].w*(a[j].r-a[j].l);
// x-=a[j].r-a[j].l;
// }
// else{
// res+=a[j].w*x;
// x=0;
// }
// //cerr<<res<<" ";
// }
//cerr<<endl;
ans=max(res,ans);
//cout<<res<<" ";
// res=prewl[n];
// x=m-prel[n];
// p = lower_bound(suflr.begin()+i+1, suflr.end(), x , greater<int>()) - suflr.begin();
//cerr<<p<<endl;
x-=suflr[p];
res+=sufwlr[p];
res+=x*a[p-1].w;
for(int j=n;j>i&&x>0;j--){
if(x>a[j].r-a[j].l){
res+=a[j].w*(a[j].r-a[j].l);
x-=a[j].r-a[j].l;
}
else{
res+=a[j].w*x;
x=0;
}
}
res+=a[i].w*x;
cout<<res<<endl;
ans=max(res,ans);
}
cout<<ans<<endl;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
solve();
// ll t;
// cin>>t;
// while(t--){
// solve();
// }
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3592kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
125 95 113 172 179 179
result:
wrong answer 1st lines differ - expected: '109', found: '125'