Cow Acrobats
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4998   Accepted: 1892

Description

Farmer John's N (1 <= N <= 50,000) cows (numbered 1..N) are planning to run away and join the circus. Their hoofed feet prevent them from tightrope walking and swinging from the trapeze (and their last attempt at firing a cow out of a cannon met with a dismal
failure). Thus, they have decided to practice performing acrobatic stunts. 



The cows aren't terribly creative and have only come up with one acrobatic stunt: standing on top of each other to form a vertical stack of some height. The cows are trying to figure out the order in which they should arrange themselves ithin this stack. 



Each of the N cows has an associated weight (1 <= W_i <= 10,000) and strength (1 <= S_i <= 1,000,000,000). The risk of a cow collapsing is equal to the combined weight of all cows on top of her (not including her own weight, of course) minus her strength (so
that a stronger cow has a lower risk). Your task is to determine an ordering of the cows that minimizes the greatest risk of collapse for any of the cows.

Input

* Line 1: A single line with the integer N. 



* Lines 2..N+1: Line i+1 describes cow i with two space-separated integers, W_i and S_i. 

Output

* Line 1: A single integer, giving the largest risk of all the cows in any optimal ordering that minimizes the risk.

Sample Input

3
10 3
2 5
3 3

Sample Output

2

Hint

OUTPUT DETAILS: 



Put the cow with weight 10 on the bottom. She will carry the other two cows, so the risk of her collapsing is 2+3-3=2. The other cows have lower risk of collapsing.

Source

——————————————————————————————————

题目的意思是给出每个人的力量值和体重,现在把每个人垒起来,每个人的压力等于他上面的人的总质量减去他的力量,求怎么排最大危险系数最小

思路:贪心把力量和体重之和大的排下面

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <vector>
using namespace std;
#define inf 0x3f3f3f3f
#define LL long long int n;
struct node{
int w,s;
}p[100005]; bool cmp(node a,node b)
{
return a.w+a.s<b.w+b.s;
} int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
scanf("%d%d",&p[i].w,&p[i].s);
sort(p,p+n,cmp);
int mx=-p[0].s;
int sum=0;
for(int i=0;i<n-1;i++)
{
sum+=p[i].w;
mx=max(mx,sum-p[i+1].s);
}
printf("%d\n",mx);
} return 0;
}

POJ3045 Cow Acrobats 2017-05-11 18:06 31人阅读 评论(0) 收藏的更多相关文章

  1. Catch That Cow 分类: POJ 2015-06-29 19:06 10人阅读 评论(0) 收藏

    Catch That Cow Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 58072   Accepted: 18061 ...

  2. {A} + {B} 分类: HDU 2015-07-11 18:06 6人阅读 评论(0) 收藏

    {A} + {B} Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  3. Codeforces777D Cloud of Hashtags 2017-05-04 18:06 67人阅读 评论(0) 收藏

    D. Cloud of Hashtags time limit per test 2 seconds memory limit per test 256 megabytes input standar ...

  4. POJ3111 K Best 2017-05-11 18:12 31人阅读 评论(0) 收藏

    K Best Time Limit: 8000MS   Memory Limit: 65536K Total Submissions: 10261   Accepted: 2644 Case Time ...

  5. HDU2544 最短路 2017-04-12 18:51 31人阅读 评论(0) 收藏

    最短路 Time Limit : 5000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submissio ...

  6. 善用VS中的Code Snippet来提高开发效率 分类: C# 2015-01-22 11:06 69人阅读 评论(0) 收藏

    前言  在谈谈VS中的模板中,我介绍了如何创建项目/项模板,这种方式可以在创建项目时省却不少重复性的工作,从而提高开发效率.在创建好了项目和文件后,就得开始具体的编码了,这时又有了新的重复性工作,就是 ...

  7. HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏

    Automatic Judge Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others ...

  8. Rebuild my Ubuntu 分类: ubuntu shell 2014-11-08 18:23 193人阅读 评论(0) 收藏

    全盘格式化,重装了Ubuntu和Windows,记录一下重新配置Ubuntu过程. //build-essential sudo apt-get install build-essential sud ...

  9. 移植QT到ZedBoard(制作运行库镜像) 交叉编译 分类: ubuntu shell ZedBoard OpenCV 2014-11-08 18:49 219人阅读 评论(0) 收藏

    制作运行库 由于ubuntu的Qt运行库在/usr/local/Trolltech/Qt-4.7.3/下,由makefile可以看到引用运行库是 INCPATH = -I/usr//mkspecs/d ...

随机推荐

  1. php 随笔算法

    <?  //--------------------  // 基本数据结构算法 //--------------------  //二分查找(数组里查找某个元素)  function bin_s ...

  2. Linux Shell中有三种引号的用法

    Linux Shell中有三种引号,分别为双引号(" ").单引号(' ')以及反引号(` `). 其中双引号对字符串中出现的$.''.`和\进行替换:单引号不进行替换,将字符串中 ...

  3. hdoj1087 (DP--LIS)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1087 思路:这题很简单了,纯LIS的解法,没有一点变形,由于数据小,使用O(n^2)LIS解法就足够了 ...

  4. python之生产者消费者模型

    #Auther Bob #--*--conding:utf-8 --*-- #生产者消费者模型,这里的例子是这样的,有一个厨师在做包子,有一个顾客在吃包子,有一个服务员在储存包子,这个服务员我们就可以 ...

  5. [leetcode]269. Alien Dictionary外星字典

    There is a new alien language which uses the latin alphabet. However, the order among letters are un ...

  6. IIS PHP Warning: Unknown: open(c:\\php\\tmp\\sess_xxx, O_RDWR) failed: Permission denied (13) in Unknown on line 0

    出现这个问题的原因是你修改了php保存session的路径,但没有给用户访问该目录的权限.   右键该目录,给users用户组读.写的权限.

  7. Linq和EF 做 单一条件查询 和 复合条件 查询 以及 多表 联合查询 示例

    单一条件查询: var table2Object = (from t1 in db.table1 join t2 in db.table2 on t1.id equals t2.id select t ...

  8. 将对象转为json,加入到HttpResponseMessage中

    需要引用程序集: System.Net.Http System.Web System.Web.Extensions Code: using System; using System.Collectio ...

  9. Linux readelf命令

    一.简介 readelf用来显示一个或者多个elf格式的目标文件的信息,可以通过它的选项来控制显示哪些信息.这里的elf-file(s)就表示那些被检查的文件.可以支持32位,64位的elf格式文件, ...

  10. CreateThread

    CreateThread(NULL,0,ReportResultThread,this,0,&g_dwThreadId) 2. 参数说明: 第一个参数 lpThreadAttributes 表 ...