QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#726273#9529. Farm ManagementrdcamelotWA 0ms3532kbC++201.3kb2024-11-08 22:40:372024-11-08 22:40:39

Judging History

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

  • [2024-11-08 22:40:39]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3532kb
  • [2024-11-08 22:40:37]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using i64=long long;
using u64=unsigned long long;
#define ll long long
const int inf=1e9;
const ll inff=1e18;
using i128=__int128;

void solve(){
    int n,m;
    cin>>n>>m;
    vector<pair<int,pair<int,int>>> a(n);
    for(int i=0;i<n;i++){
        cin>>a[i].first>>a[i].second.first>>a[i].second.second;
    }
    sort(a.begin(),a.end(),greater());
    vector<i64> del(n),l(n),delpro(n);
    i64 sum=0ll;
    for(int i=0;i<n;i++){
        m-=a[i].second.first;
        del[i]=a[i].second.second-a[i].second.first;
        delpro[i]=1ll*a[i].first*del[i];
        l[i]=1ll*a[i].first*a[i].second.first;
        sum+=l[i];
    }
    for(int i=1;i<n;i++){
        del[i]+=del[i-1];
        delpro[i]+=delpro[i-1];
    }
    // sum 所有下限的和,del r-l的和,delpro 对应增量的和
    // id是完全能加满的位置
    i64 ans=sum+m*a[0].first;
    for(int i=1;i<n;i++){
        int id=upper_bound(del.begin(),del.end(),a[i].second.first+m)-del.begin()-1;
        id=min(id,i-1);
        ans=max(sum-l[i]+(a[i].second.first+m-del[id])*a[id+1].first+delpro[id],ans);
    }
    cout<<ans<<'\n';
}

int main(){
    ios::sync_with_stdio(0);cin.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: 3532kb

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

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'