#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<sstream>
using namespace std;
#define L 101
#define MAX 0x3f
int n;
struct homework{
int date;
int score;
}a[L];
int sum=0;
int g[L]; //站位
bool flag;
bool comp(homework a,homework b){
return a.score>b.score; //降序排列
}
int main()
{
//1.get
cin >> n;
for(int i=1;i<=n;i++){
cin >> a[i].date >> a[i].score; //期限 + 学分
}
//2.sort
sort(a+1,a+n+1,comp);
//3.do
for(int i=1;i<=n;i++){
flag=false;
for(int j=a[i].date;j>=1;j--){
if(!g[j]){ //可以执行
g[j]=1; //占位
sum+=a[i].score;
flag=true;
}
}
//罗生门思想
if(!flag){ //无法按时执行 => 从后往前任选1个
for(int j=n;j>=1;j--){
if(!g[j]){g[j]=1;break;}
}
}
}
cout << sum;
return 0;
}
/*
7
1 6
1 7
3 2
3 1
2 4
2 5
6 1
*/
//cout << "输入:"
结果: