1 条题解
-
0Guest LV 0 MOD
-
0
# include <iostream> # include <cstdio> # include <cstring> # include <queue> # include <algorithm> using namespace std; const int maxn=1000100; priority_queue <int> q; struct homework{ int time,score; }hw[maxn]; int n; int hwcomp(const homework &a,const homework &b) { return a.time>b.time; } inline void read(int &x) { char ch=getchar(); while(ch<'0'||ch>'9') ch=getchar(); x=0; while(ch>='0'&&ch<='9') { x*=10;x+=ch-'0'; ch=getchar(); } } int main() {int maxt,k=0,ans=0,time,score; // freopen("credits.in","r",stdin); // freopen("credits.out","w",stdout); scanf("%d",&n); for(int i=0;i<n;++i) { read(time);hw[i].time=time; read(score);hw[i].score=score; } sort(hw+0,hw+n,hwcomp); maxt=hw[0].time; for(int i=maxt;i>=1;--i) { while(hw[k].time==i&&k<n) q.push(hw[k++].score); if(!q.empty()) {ans+=q.top(); q.pop(); } } printf("%d\n",ans); }
- 1