换一个码风?
#include<bits/stdc++.h>
#define _max(a,b) (a>b) ? (a):(b)
#define For(i,a,b) for(int i = (a);i<(b);++ i)
#define _for(i,a,b) for(int i = (a);i<=(b);++ i)
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;
const int N = 2000010;
template<typename T> void get(T &x){
int c,f;while(!isdigit(c = getchar())&&c!='-');c == '-'?(x = 0,f = 1):(f = 0,x = c - '0');
while(isdigit(c = getchar()))x = (x<<1) + (x<<3) + c - '0';if(f)x = -x;
}
template<typename T> void write(T x){
if(x<10){
putchar(x + '0');
}
else{
write(x/10);
write(x%10);
}
}
void ckmax(int &x,const int &y){
if(x<y)x = y;
return;
}
int mx;
struct point{
int t,w;
void scan(){
get(t),get(w);
ckmax(mx,t);
return;
}
bool operator < (const point &rhs) const{
return w > rhs.w;
}
}a[N];
int n;
int lst[N];
int main(){
get(n);
_for(i,1,n){
a[i].scan();
}
sort(a+1,a+1+n);
_for(i,1,mx){
lst[i] = i;
}
ll res = 0;
_for(i,1,n){
if(lst[a[i].t]){
res += a[i].w;
lst[a[i].t] = lst[lst[a[i].t] - 1];
}
}
cout<<res;
return 0;
}