QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#408575#6397. Master of Both IIIKotomiWA 1ms3588kbC++201.3kb2024-05-10 18:37:282024-05-10 18:37:30

Judging History

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

  • [2024-05-10 18:37:30]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3588kb
  • [2024-05-10 18:37:28]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
bool cmp(int a,int b){
    return a>b;
}
void work(){
    int n,m;
    cin>>n>>m;
    vector<int> a(n),b(n),c(n);
    int ans=0;
    for (int i = 0; i < n; ++i) {
        cin>>a[i]>>b[i];
        c[i]=b[i]-a[i];//计算独居带来的收益
        ans+=a[i];//首先默认群居
    }
    if(n==1){//特判
        cout<<b[0]<<endl;
        return;
    }else if(n==2){
        if(m>2)cout<<max(b[0]+b[1],a[0]+a[1]);
        else cout<<a[0]+a[1]<<endl;
        return;
    }
    sort(c.begin(),c.end(),cmp);
    int x=m-n;
    int y=x;
    for (int i = 0; i < c.size(); ++i) {
        if(c[i]<=0||y<=0)break;
        ans+=c[i];//将这个人拆出来独居
        y--;//可独居数量减1
        if(i==c.size()-2){//如果是最后两个,拆分后必然导致出现两个独居
            if(c[i+1]>0){
                ans+=c[i+1];
                break;
            }
            if(abs(c[i])>abs(c[i+1]))ans+=c[i+1];//考虑最后两人是否要拆分
            else ans-=c[i];
            break;
        }
    }
    cout<<ans<<endl;
}
signed main(){
    int t;
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    cin>>t;
    while(t--){
        work();
    }
}
//
// Created by johntime on 24-5-10.
//

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3588kb

input:

3
2 1 2

output:

2
0
0

result:

wrong answer 1st numbers differ - expected: '45', found: '2'