首页 技术 正文
技术 2022年11月12日
0 收藏 924 点赞 3,628 浏览 2007 个字

Have you ever heard the story of Blue.Mary, the great civil engineer? Unlike Mr. Wolowitz, Dr. Blue.Mary has accomplished many great projects, one of which is the Guanghua Building. 
  The public opinion is that Guanghua Building is nothing more than one of hundreds of modern skyscrapers recently built in Shanghai, and sadly, they are all wrong. Blue.Mary the great civil engineer had try a completely new evolutionary building method in project of Guanghua Building. That is, to build all the floors at first, then stack them up forming a complete building. 
  Believe it or not, he did it (in secret manner). Now you are face the same problem Blue.Mary once stuck in: Place floors in a good way. 
  Each floor has its own weight w i and strength s i. When floors are stacked up, each floor has PDV(Potential Damage Value) equal to (Σw j)-s i, where (Σwj) stands for sum of weight of all floors above. 
  Blue.Mary, the great civil engineer, would like to minimize PDV of the whole building, denoted as the largest PDV of all floors. 
  Now, it’s up to you to calculate this value. 

Input  There’re several test cases. 
  In each test case, in the first line is a single integer N (1 <= N <= 10 5) denoting the number of building’s floors. The following N lines specify the floors. Each of them contains two integers w i and s i (0 <= w i, s i <= 100000) separated by single spaces. 
  Please process until EOF (End Of File). 
Output  For each test case, your program should output a single integer in a single line – the minimal PDV of the whole building. 
  If no floor would be damaged in a optimal configuration (that is, minimal PDV is non-positive) you should output 0. 
Sample Input

3
10 6
2 3
5 4
2
2 2
2 2
3
10 3
2 5
3 3

Sample Output

1
0
2
#include<iostream>
#include<cstdio>
#include<cstring>
#include<sstream>
#include<algorithm>
#include<queue>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<fstream>
#include<memory>
#include<string>
using namespace std;
typedef long long LL;
#define MAXN 100008
#define INF 1000000009
struct node
{
int w, s;
}a[MAXN];
int n;
bool cmp(node a, node b)
{
return a.w - b.s < b.w - a.s;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
for (int i = ; i < n; i++)
scanf("%d%d", &a[i].w, &a[i].s);
sort(a, a + n, cmp);
LL sum = a[].w,ans = ;
for (int i = ; i < n; i++)
{
LL tmp = sum-a[i].s;
ans = max(ans, tmp);
sum += a[i].w;
}
printf("%lld\n", ans);
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,082
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,556
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,405
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,179
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,815
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,898