Chri_K

堆积木(贪心)
#include<iostream>
#include <algorithm>
using namespace std;
struct node
{
    int w;
    int f; 
     int s; 
}p[50010];
bool cmp(node x,node y)
{
    return x.s < y.s;
}
int main()
{
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
       {
        cin>>p[i].w>>p[i].f;
        p[i].s=p[i].w+p[i].f;
    }
    sort(p+1,p+n+1,cmp);
    int ans=-100000000;
    int temp=0;
    for(int i=1;i<=n;i++)
    {
        ans=max(ans,temp-p[i].f);
        temp+=p[i].w;
    }
    cout<<ans;
    return 0;
}

 

posted on 2020-10-19 22:45  Chri_K  阅读(111)  评论(0编辑  收藏  举报