gym 100484

来源:互联网 发布:java分母最小化 编辑:程序博客网 时间:2024/06/03 09:03

贪心,mr很久以前讲过,但是忘了。

跟国王游戏很像,都是贪心,并且是两个东西,一个是乘法,一个是加法.

贪心w+s,因为...推出来的

考虑:上下两个是否要交换?列出关系式,然后推

#include<iostream>#include<algorithm>using namespace std;typedef long long ll;ll n,ans,tot;ll c[100010],w[100010],s[100010];bool cp(ll x,ll y){return w[x]+s[x]>w[y]+s[y];}int main(){cin>>n;for(int i=1;i<=n;i++){cin>>w[i]>>s[i];tot+=w[i];c[i]=i;}sort(c+1,c+n+1,cp);ans=-1<<30;for(int i=1;i<=n;i++){tot-=w[c[i]];ans=max(ans,tot-s[c[i]]);}cout<<ans<<endl;return 0;}


0 0