记录编号 606620 评测结果 AAAAAAAAAA
题目名称 3719.有n种物品 最终得分 100
用户昵称 Gravatar123 是否通过 通过
代码语言 C++ 运行时间 0.173 s
提交时间 2025-10-01 15:03:48 内存使用 3.90 MiB
显示代码纯文本
#include <bits/stdc++.h>
#define fi first
#define sd second
using namespace std;
priority_queue<pair<int,int> > q; 
int t,x,y,f=0;
long long ret[3];
int main() {
    freopen("nit.in","r",stdin);
    freopen("nit.out","w",stdout);
    cin>>t;
    while (t--)
    {
        scanf("%d%d",&x,&y);
        q.push({x-y,y});
    }
    while (!q.empty())
    {
        pair<int,int> t=q.top();q.pop();
		if (t.fi>=0) 
		{
			ret[f]+=t.fi+t.sd,ret[f^1]+=t.sd;
		} 
		else
		{
			ret[0]+=t.fi+t.sd,ret[1]+=t.sd;
		}
		f^=1; 
   	}
    cout<<ret[0]-ret[1];
}