| 比赛 | 
    20120413 | 
    评测结果 | 
    AWWWWWWAWAWA | 
    | 题目名称 | 
    工作进度 | 
    最终得分 | 
    33 | 
    | 用户昵称 | 
    苏轼 | 
    运行时间 | 
    0.000 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.00 MiB  | 
    | 提交时间 | 
    2012-04-13 21:48:07 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<cstdlib>
using namespace std;
int n;
struct hehe
{
	int a,b;
}w[100001];
unsigned long long answer=0;
int q[100001][2],tou=1,wei=1,ji=0;
int cmp(const void *a,const void *b);
int main()
{
	freopen ("joba.in","r",stdin);
	freopen ("joba.out","w",stdout);
	cin>>n;
	for (int i=0;i<n;i++)
	{
		cin>>w[i].a>>w[i].b;
	}
	qsort(w,n,sizeof(w[0]),cmp);
	for (int i=0;i<n;i++)
	{
		if (ji<w[i].a)
		{
			ji++;
			q[wei][0]=w[i].a;
			q[wei][1]=w[i].b;
			wei++;
		}
		else
		{
			if (q[tou][1]<w[i].b)
			{
				tou++;
				q[wei][0]=w[i].a;
				q[wei][1]=w[i].b;
				wei++;
			}
		}
	}
	for (int i=tou;i<wei;i++)
		answer+=q[i][1];
	cout<<answer;
	return 0;
}
int cmp(const void *e,const void *f)
{
	struct hehe *c=(struct hehe *)e;
	struct hehe *d=(struct hehe *)f;
	if (c->a==d->a)
		return (c->b > d->b) ?1:-1;
	else
		return (c->a > d->a) ?1:-1;
}