比赛 |
20251001国庆欢乐赛1 |
评测结果 |
AAWWWWWWWW |
题目名称 |
有n种物品 |
最终得分 |
20 |
用户昵称 |
秋_Water |
运行时间 |
0.541 s |
代码语言 |
C++ |
内存使用 |
5.17 MiB |
提交时间 |
2025-10-01 11:33:22 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int n,a[N],b[N];
map<int,int>mapp;
priority_queue<int>q;
int main(){
freopen("nit.in","r",stdin);
freopen("nit.out","w",stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
mapp[a[i]]=b[i];
q.push(-a[i]);
}
int ans=0;
while(!q.empty()){
int c=-q.top();
q.pop();
int d;
if(-q.top()>mapp[c]&&!q.empty()){
d=-q.top();
q.pop();
q.push(-mapp[c]);
}
else{
d=mapp[c];
}
ans+=(c-d);
}
cout<<ans;
return 0;
}