1 #include <iostream>
2 #include <cstdio>
3 #include <queue>
4 #include <algorithm>
5 using namespace std;
6 int n;
7 struct data{long long t,v;}a[100010];
8 long long ans,now;
9 priority_queue<long long>q;
10 bool cmp(data a,data b) {return a.t<b.t;}
11 inline int read()
12 {
13 int f=1,ans=0;
14 char c;
15 while (!isdigit(c=getchar())) if (c==‘-‘) f=-1;
16 ans=c-‘0‘;
17 while (isdigit(c=getchar())) ans=ans*10+c-‘0‘;
18 return ans*f;
19 }
20 int main()
21 {
22 scanf("%d",&n);
23 for (int i=1;i<=n;i++) a[i].t=read(),a[i].v=read();
24 a[++n].t=0; a[n].v=0;
25 sort(a+1,a+n+1,cmp);
26 now=1000000000;
27 for (int i=n;i>=1;i--)
28 {
29 while (now>a[i].t && q.size()>0)
30 {
31 now--;
32 ans+=q.top();
33 q.pop();
34 }
35 now=a[i].t;
36 q.push(a[i].v);
37 }
38 printf("%lld\n",ans);
39 return 0;
40 }