QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#704509#9529. Farm Managementocharin#WA 0ms3884kbC++202.8kb2024-11-02 20:06:512024-11-02 20:06:55

Judging History

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

  • [2024-11-02 20:06:55]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3884kb
  • [2024-11-02 20:06:51]
  • 提交

answer

/*

                                _/                                      _/
       _/_/        _/_/_/      _/_/_/        _/_/_/      _/  _/_/               _/_/_/
    _/    _/    _/            _/    _/    _/    _/      _/_/          _/       _/    _/
   _/    _/    _/            _/    _/    _/    _/      _/            _/       _/    _/
    _/_/        _/_/_/      _/    _/      _/_/_/      _/            _/       _/    _/

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

using namespace std;

void solve(){
    int n,k;
    cin>>n>>k;
    vector<array<int,3>>a(n);
    for(auto &[x,y,z]:a) cin>>x>>y>>z;
    sort(a.begin(),a.end(),greater());
    int tmp=0;
    vector<int>use(n);
    for(int i=0;i<n;++i) use[i]=a[i][2],tmp+=use[i];
    for(int i=n-1;i>=0;--i){
        int x=a[i][2]-a[i][1];
        if(tmp-x>k){
            tmp-=x;
            use[i]=a[i][1];
        }
        else{
            use[i]-=tmp-k;
            tmp=i;
            break;
        }
    }
    vector<int>s(n);
    s[0]=use[0]*a[0][0];
    for(int i=1;i<n;++i) s[i]=s[i-1]+use[i]*a[i][0];
    vector<int>ma(n),mi(n),sl(n),sr(n);
    ma[0]=a[0][0]*a[0][2];
    mi[0]=a[0][0]*a[0][1];
    sl[0]=a[0][1];
    sr[0]=a[0][2];
    for(int i=1;i<n;++i) ma[i]=ma[i-1]+a[i][2]*a[i][0];
    for(int i=1;i<n;++i) mi[i]=mi[i-1]+a[i][1]*a[i][0];
    for(int i=1;i<n;++i) sl[i]=sl[i-1]+a[i][1];
    for(int i=1;i<n;++i) sr[i]=sr[i-1]+a[i][2];
    // for(int i=0;i<n;++i) cout<<mi[i]<<" \n"[i==n-1];
    // for(int i=0;i<n;++i) cout<<ma[i]<<" \n"[i==n-1];
    // for(int i=0;i<n;++i) cout<<sl[i]<<" \n"[i==n-1];
    // for(int i=0;i<n;++i) cout<<sr[i]<<" \n"[i==n-1];
    // cout<<endl;
    int res=0;
    for(int i=0;i<=tmp;++i){
        int ans=0;
        if(i) ans+=ma[i-1];
        int rem=k;
        if(i) rem-=sr[i-1];
        rem-=sl[n-1]-sl[i];
        ans+=mi[n-1]-mi[i];
        ans+=rem*a[i][0];
        res=max(res,ans);
    }
    for(int i=tmp+1;i<n;++i){
        int ans=0;
        int rem=k;
        rem-=sl[n-1]-sl[i];
        ans+=mi[n-1]-mi[i];
        int l=tmp,r=i-1;
        auto check=[&](int x)->bool{
            if(sr[x]+sl[i-1]-sl[x]>=rem) return 1;
            else return 0;
        };
        while(l<r){
            int mid=l+r+1>>1;
            if(check(mid)) l=mid;
            else r=mid-1;
        }
        if(l==i-1){
            ans+=ma[l];
            rem-=sr[l];
            ans+=rem*a[i][0];
        }
        else{
            ans+=ma[l];
            rem-=sr[l];
            ans+=mi[i-1]-mi[l];
            rem-=sl[i-1]-sl[l];
            ans+=rem*a[l+1][0];
        }
        res=max(res,ans);
    }
    cout<<res<<"\n";
}


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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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:

44007019

result:

wrong answer 1st lines differ - expected: '35204500', found: '44007019'