QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#683144 | #9529. Farm Management | potential# | WA | 1ms | 5696kb | C++20 | 1.2kb | 2024-10-27 19:02:25 | 2024-10-27 19:02:25 |
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+1,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();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5696kb
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: 5680kb
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: 5640kb
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'