hdu4296Buildings 贪心

来源:互联网 发布:php文件管理插件 简洁 编辑:程序博客网 时间:2024/04/20 08:35
//给出wi , si , 求出对应//segma(wj)-si  , segma(wj)-si为在第i个位置前面的所有位置wi之和//求出segma(wj)-si 的最大值的最小值//可以知道w越大越后,s越大越后,可以按照(s+w)越大越后排序#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>using namespace std ;const int maxn = 1e5+10 ;typedef long long  ll ;struct node{    int w , s ;    bool operator < (const struct node tmp)const    {        return (w+s)<(tmp.w + tmp.s) ;    }}a[maxn] ;int main(){    int n ;    while(~scanf("%d" , &n))    {        for(int i = 1;i <= n;i++)        scanf("%d%d"  , &a[i].w , &a[i].s) ;        sort(a+1 , a+1+n) ;        ll ans = 0;        ll sum = 0;        for(int i = 1;i <= n;i++)        {            ans = max(ans , sum - a[i].s) ;            sum += a[i].w ;        }        cout<<ans<<endl;    }}
0 0