QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#702145 | #9529. Farm Management | Yoralen | WA | 0ms | 5996kb | C++14 | 1.0kb | 2024-11-02 15:23:07 | 2024-11-02 15:23:09 |
Judging History
answer
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
#define int long long
const int N=100005;
struct node{int v,l,r,d;}a[N];
int sml[N],smr[N],sl[N],sr[N],sd[N];
int n,m,ans;
bool cmp(node A,node B){return A.v<B.v;}
signed main(){
int i;
scanf("%lld%lld",&n,&m);
for(i=1;i<=n;i++){
scanf("%lld%lld%lld",&a[i].v,&a[i].l,&a[i].r);
a[i].d=a[i].r-a[i].l+1;
}
sort(a+1,a+1+n,cmp);
for(i=1;i<=n;i++){
sl[i]=sl[i-1]+a[i].l;
sr[i]=sr[i-1]+a[i].r;
sd[i]=sd[i-1]+a[i].d;
sml[i]=sml[i-1]+a[i].l*a[i].v;
smr[i]=smr[i-1]+a[i].r*a[i].v;
}
for(i=1;i<=n;i++){
int spl=sl[i-1],spr=sr[n]-sr[i];
if(spl+spr<=m){
int dlt=m-spl-spr;
ans=max(ans,sml[i-1]+smr[n]-smr[i]+dlt*a[i].v);
}
else{
int dlt=spl+spr-m;
int L=i,R=n,rs=L;
while(L<=R){
int mid((L+R)>>1);
if(sd[mid]-sd[i]<=dlt){
rs=mid,L=mid+1;
}
else R=mid-1;
}
ans=max(ans,sml[i-1]+sml[rs]-sml[i]+smr[n]-smr[rs]-a[rs+1].v*(dlt-(sd[rs]-sd[i])));
}
}
printf("%lld\n",ans);
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 5996kb
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: 0ms
memory: 5860kb
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:
40474895
result:
wrong answer 1st lines differ - expected: '35204500', found: '40474895'