1 #include<cstdio>
2 #include<cstdlib>
3 #include<cstring>
4 #include<iostream>
5 #include<algorithm>
6 #include<queue>
7 using namespace std;
8 #define Maxn 100010
9 #define LL long long
10
11 struct node
12 {
13 int d,w;
14 friend bool operator < (node x,node y)
15 {
16 return x.w>y.w;
17 }
18 }t[Maxn];
19
20 priority_queue<node > q;
21
22 bool cmp(node x,node y) {return x.d<y.d;}
23
24 int main()
25 {
26 int n;
27 scanf("%d",&n);
28 for(int i=1;i<=n;i++) scanf("%d%d",&t[i].d,&t[i].w);
29 sort(t+1,t+1+n,cmp);
30 LL ans=0;int cnt=0;
31 for(int i=1;i<=n;i++)
32 {
33 if(t[i].d<=cnt)
34 {
35 if(q.top().w<t[i].w)
36 {
37 ans+=t[i].w-q.top().w;
38 q.pop();
39 q.push(t[i]);
40 }
41 }
42 else
43 {
44 q.push(t[i]);
45 ans+=t[i].w;
46 cnt++;
47 }
48 }
49 printf("%lld\n",ans);
50 return 0;
51 }