UESTC - 1045 Lovely princess (模拟)水

UESTC - 1045
Time Limit:                                                        1000MS                        Memory Limit: 65535KB 64bit IO Format:                            %lld & %llu                       

Status

Description

There are n jobs you need to complete. However, complete the ith job you capability must be no less than vi. If you have completed the ith job, your capability will increase ai.

Then the question is coming, what is the minimum initial capability value if you are required to complete all of the n jobs.

Note that there is no restriction on the order you complete them. That is to say, you can decide the order by your own.

Input

The first line contains a single integer n, which is the number of jobs you need to complete.

Then each of the following n lines contains 2 integers vi and ai, which are described above.

1n1000,0vi1000000,0ai1000

Output

Print the answer in one line.

Sample Input

1
2 1

Sample Output

2

Hint

Source

The 13th UESTC Programming Contest Preliminary
//题意:输入n个数,再输入n个a[i],w[i];
给你n个任务,每完成一个一个任务你的能力值会加上对应任务的权值,完成某个任务的要求是,你的能力值要大于这个任务的a[i],问初始的能力值最小是多大?
//思路:
直接模拟。
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define N 1010
using namespace std;
struct zz
{
	int v;
	int w;
}p[N];
bool cmp(zz a,zz b)
{	
	if(a.v==b.v)
		return a.w<b.w;
	return a.v<b.v;
}
int main()
{
	int n,m,i,j,k;
	while(scanf("%d",&n)!=EOF)
	{
		for(i=0;i<n;i++)
			scanf("%d%d",&p[i].v,&p[i].w);
		sort(p,p+n,cmp);
		int k=p[0].v,kk=0;
		m=k;
		for(i=1;i<n;i++)
		{
			m+=p[i-1].w;
			if(m<p[i].v)
			{
				kk=p[i].v-m;
				k+=kk;m+=kk;
			}
		}
		printf("%d\n",k);
	}
	return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值