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. pyorient

    简介 pyorient是orientdb的python库 该库提供两种访问orientdb的方式:1.client 的方式 2.ogm 的方式(类似于ORM) 由于OGM 封装了client,且由于O ...

  2. python字符串填充(转)

    ljust()方法返回字符串左对齐的字符串长度宽度.填充是通过使用指定的fillchar(默认为空格).如果宽度小于len(s)返回原始字符串.语法 以下是ljust()方法的语法: str.ljus ...

  3. chnagyong sql

    select gid,count(distinct mid) from members group by gid mysql> SELECT IFNULL(NULL,); mysql> 1 ...

  4. Anaconda中python加入环境变量

    1.我的电脑---高级系统设置 2.选中环境变量,保存. 3.在系统环境变量PATH中,加入Anaconda3及Script路径加入其中 4.测试python

  5. java rsa 加解密

    参考 http://blog.csdn.net/a394268045/article/details/52232120 package rsa; import org.apache.commons.c ...

  6. 《Visual C++开发实战1200例 第1卷》扫描版[PDF]

    [内容简介:] <Visual C++开发实战1200例(第1卷)>是“软件开发实战1200例”丛书之一.<Visual C++开发实战1200例(第1卷)>,编程实例的四库全 ...

  7. 【校招面试 之 C/C++】第2题 函数模板、类模板、特化、偏特化

    1.C++模板 说到C++模板特化与偏特化,就不得不简要的先说说C++中的模板.我们都知道,强类型的程序设计迫使我们为逻辑结构相同而具体数据类型不同的对象编写模式一致的代码,而无法抽取其中的共性,这样 ...

  8. day12:vcp考试

    Q221. An administrator is creating a new Platform Service Controller Password Policy with the follow ...

  9. [udemy]WebDevelopment_How the Internet Works

    Browsing the web Enter google.com, who is this google.com This question gets asked all the way down ...

  10. Mint UI 之 Swipe 组件

    #为什么不显示内容? 一定要指定 mt-swipe 元素的宽和高. <mt-swipe :auto="4000" class="swipe"> &l ...