比赛 20251001国庆欢乐赛1 评测结果 AAAWWAAAWA
题目名称 有n种物品 最终得分 70
用户昵称 左清源 运行时间 0.135 s
代码语言 C++ 内存使用 3.91 MiB
提交时间 2025-10-01 09:58:08
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int n;
ll ans;
vector<ll>a;
bool cmp(ll a,ll b){
    return a>b;
}
int main(){
    freopen("nit.in","r",stdin);
    freopen("nit.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        ll x,y;
        scanf("%lld %lld",&x,&y);
        if(x==y)continue;
        if(x<y)ans+=x-y;
        else a.push_back(x-y); 
    }
    sort(a.begin(),a.end());
    for(int i=0;i<a.size();i++){
        if(i&1)ans-=a[i];
        else ans+=a[i]; 
    }
    printf("%lld\n",ans);
    return 0;
}