QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#683042 | #9529. Farm Management | potential# | WA | 1ms | 5760kb | C++20 | 1.1kb | 2024-10-27 18:29:55 | 2024-10-27 18:29:56 |
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];
map<int,int> mp;
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;
}
sort(sum+1,sum+1+n);
int ans=nw;
for(int i=1;i<=n;i++){
int pos=upper_bound(sum+1,sum+1+i,a[i].l+m-now)-sum;
ans=max(ans,nw+ss[pos-1]-(a[i].l)*a[i].w+a[i].w*(m-now+a[i].l-sum[pos-1]));
// cout<<m<<" "<<now<<" "<<sum[pos-1]<<"\n";
}
cout<<ans<<"\n";
}
signed main(){
IOS
int T=1;
// cin>>T;
while(T--){
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5652kb
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: 5760kb
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:
34859047
result:
wrong answer 1st lines differ - expected: '35204500', found: '34859047'