I - Sobytiynyy Proyekt Casino Gym - 102299I

求最佳玩家在最糟糕情况下最大收益

#include 
#define ll long long
using namespace std;

struct node
{
    ll p;
    ll f;
}a[100005];
bool cmp(struct node a,struct node b)
{
    return a.f<b.f;
}
int main()
{
    ll n;
    cin>>n;
    ll sum=0;
    ll Max=-1e9;
    for(ll i=0;i<n;++i)
    {
        cin>>a[i].p>>a[i].f;
    }
    sort(a,a+n,cmp);
    for(int i=0;i<n;++i)
    {
        sum=sum+a[i].p;
        Max=max(Max,sum-a[i].f);
    }
    cout<<Max<<endl;
    return 0;
}

你可能感兴趣的:(I - Sobytiynyy Proyekt Casino Gym - 102299I)