刚才入门赛H题求助
  • 板块灌水区
  • 楼主are_you_sure
  • 当前回复20
  • 已保存回复20
  • 发布时间2024/9/14 21:13
  • 上次更新2024/9/15 08:06:49
查看原帖
刚才入门赛H题求助
1367333
are_you_sure楼主2024/9/14 21:13

就是考试那题,50分,WA on 2,4,6,7,8,10,14,18,19,20

#include<iostream>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define int long long
struct ex{
    int a,b;
    int fc;
}e[1001];
bool cmp(ex a,ex b){
    return a.fc<b.fc;
}
signed main(){
    int n,win=0,lost=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>e[i].a;
    }
    for(int i=0;i<n;i++){
        cin>>e[i].b;
        e[i].fc=e[i].b-e[i].a;
        if(e[i].fc<0)win++;
        else lost++;
    }
    if(win>lost){
        cout<<0;
        return 0;
    }
    sort(e,e+n,cmp);
    int sum=0;
    for(int i=0;i<n;i++){
        if(e[i].fc>=0){
            sum+=e[i].fc+1;
            lost--;
            win++;
        }
        if(win>lost)break;
    }
    cout<<sum;
    return 0;
}
2024/9/14 21:13
加载中...