#28866: 這樣寫有什麼問題??


wallacechu0409@gmail.com (Wallace Chu)


#include <bits/stdc++.h>

using namespace std;

 

int n;

struct kk{

int m,t;

};

kk p[10005];

 

bool cmp(kk a,kk b){

if(a.m==b.m){

return a.t<b.t;

}

return a.m>b.m;

}

 

int main() {

ios::sync_with_stdio(0);

cin.tie(0);

cout.tie(0);

while(cin>>n){

long long sum=0;

set<int>kk;

for(int i=0;i<=10001;i++){

kk.insert(i);

}

for(int i=1;i<=n;i++){

cin>>p[i].m>>p[i].t;

}

sort(p+1,p+n+1,cmp);

for(int i=1;i<=n;i++){

if(*((kk.lower_bound(p[i].t)))<=p[i].t){

kk.erase(kk.lower_bound(p[i].t));

sum=sum+p[i].m;

}

}

cout<<sum<<'\n';

}

return 0;

}