Pagini recente » Cod sursa (job #2793057) | Cod sursa (job #1061545) | Cod sursa (job #1825830) | Cod sursa (job #858227) | Cod sursa (job #554908)
Cod sursa(job #554908)
#include<cstdio>
#include<set>
#include<algorithm>
#define Nmax 100001
using namespace std;
int N,ind[Nmax],t[Nmax],p[Nmax];
struct cmp2{
bool operator()(const int&a,const int&b) const{
return a>b;
}
};
multiset <int,cmp2> heap;
bool cmp(const int&a,const int&b){
return t[a]>t[b];
}
long long sol;
int main(){
freopen("procesor.in","r",stdin);
freopen("procesor.out","w",stdout);
scanf("%d",&N);
for(int i=1;i<=N;++i)
scanf("%d%d",&t[i],&p[i]),
ind[i]=i;
sort(ind+1,ind+N+1,cmp);
int q=1;
for(int i=t[ind[1]];i>=1;--i){
while(i==t[ind[q]] && q<=N){
heap.insert(p[ind[q]]);
q++;
}
if(!heap.empty())
heap.erase(heap.begin());
}
while(!heap.empty())
sol+=*heap.begin(),
heap.erase(heap.begin());
printf("%lld",sol);
return 0;
}