QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#772218#9529. Farm Managementshenchuan_fanWA 0ms3816kbC++201.8kb2024-11-22 17:36:142024-11-22 17:36:15

Judging History

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

  • [2024-11-22 17:36:15]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3816kb
  • [2024-11-22 17:36:14]
  • 提交

answer

#include <bits/stdc++.h>
#define int long long

using namespace std;

struct Node {
    int w, l, r;

    // 定义比较运算符
    bool operator<(const Node &other) const {
        if (w != other.w) {
            return w < other.w;
        } else {
            return (r-l)<(other.r-other.l);
        }
    }
};

void solve()
{
    int n,m;
    cin>>n>>m;
    vector<Node>res(n+1);
    int val=0;
    int tot=0;
    for(int i=1;i<=n;i++){
        int w,l,r;
        cin>>w>>l>>r;
        res[i]={w,l,r};
        val+=w*l;
        tot+=l;
    }

    sort(res.begin()+1,res.end());

    vector<int>sum(n+1,0);
    vector<int>cnt(n+1,0);

    for(int i=1;i<=n;i++){
        sum[i]=sum[i-1]+(res[i].r-res[i].l)*res[i].w;
        cnt[i]=cnt[i-1]+(res[i].r-res[i].l);
    }
    int ans=0;
    if(tot==m){
        ans=val;
    }
    for(int i=1;i<=n;i++){
        int num=tot-res[i].l;
        int now=val-res[i].w*res[i].l;
        if(m>=num){
            int need=m-num;
            int l=0,r=n-1;
            while(l<r){
                int mid=l+r+1>>1;
                if(cnt[n]-cnt[mid]+(mid>=i?0:(res[i].l))>=need)   l=mid;
                else r=mid-1;
            }
            if(cnt[n]-cnt[l]+(l>=i?0:(res[i].l))==need){
                ans=max(ans,now+sum[n]-sum[l]+(l>=i?0:(res[i].l)*res[i].w));
            }else{
                l+=1;
                int p=need-(cnt[n]-cnt[l]+(l>=i?0:(res[i].l)));
                ans=max(ans,now+sum[n]-sum[l]+(l>=i?0:(res[i].l)*res[i].w)+p*res[l-1].w);
            }
        }

    }
    
    cout<<ans<<'\n';


}

signed main() 
{	    
    ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int T=1;
    //cin>>T;
    while(T--)
    {
        solve();
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3816kb

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: 3500kb

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'