QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#748648#9529. Farm ManagementlegohuCompile Error//C++201.4kb2024-11-14 20:57:402024-11-14 20:57:41

Judging History

你现在查看的是最新测评结果

  • [2024-11-14 20:57:41]
  • 评测
  • [2024-11-14 20:57:40]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+10;
struct node{
    ll w,l,r,id;
    node(){}
    node(ll W,ll L,ll R,ll ID){
        w=W;l=L;r=R;id=ID;
    }
    friend bool operator<(const node&x,const node&y){
        return x.w>y.w;
    }
}a[N],b[N];int cur=1,usd=0;
bool cmp(const node&x,const node&y){return x.l<y.l;}
int n;
ll gnew(int m){
    ll sum=0;//cout<<m;
    ll lcur=cur;
    while(cur<=n&&b[cur].r==0)cur++;
    if(cur>n)return;
    while(b[cur].r<usd+m){
        m-=b[cur].r-usd;
        sum+=(b[cur].r-usd)*b[cur].w;
        usd=0;cur++;
    }
    sum+=m*b[cur].w;usd+=m;
    //cout<<" left with sum"<<sum<<":"<<lcur<<"->"<<cur<<" usd:"<<usd<<endl;

    return sum;
}
ll m,w[N],l[N],r[N],p;

int main(){
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        scanf("%lld %lld %lld",&w[i],&l[i],&r[i]);
        if(w[p]<w[i])p=i;
        if(w[p]==w[i]&&r[i]>r[p])p=i;
        a[i]=node(w[i],l[i],r[i],i);
    }
    ll sum=0,len=0,ans=0,ml=0;
    for(int i=1;i<=n;i++)
    {
        sum+=l[i]*w[i];len+=l[i];
        b[i]=a[i];b[i].r-=b[i].l;
    }
    sort(a+1,a+1+n,cmp);sort(b+1,b+1+n);
    ans=sum-l[p]*w[p]+(m-len+l[p])*w[p];
    sum+=gnew(m-len);a[0].l=0;
    ans=max(sum,ans);
    for(int i=1;i<=n;i++){
        sum+=gnew(a[i].l-a[i-1].l);
        ans=max(ans,sum-a[i].l*a[i].w);
    }
    cout<<ans<<endl;
    return 0;
}

Details

answer.code: In function ‘long long int gnew(int)’:
answer.code:21:14: error: return-statement with no value, in function returning ‘long long int’ [-fpermissive]
   21 |     if(cur>n)return;
      |              ^~~~~~
answer.code: In function ‘int main()’:
answer.code:37:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   37 |         scanf("%lld %lld %lld",&w[i],&l[i],&r[i]);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~