AC日记——Sagheer and Nubian Market codeforces 812c

C - Sagheer and Nubian Market

 

思路:

  二分;

 

代码:

#include <bits/stdc++.h>

using namespace std;

#define maxn 1000005
#define ll long long

ll n,s,ai[maxn],ci[maxn];

inline void in(ll &now)
{
    char Cget=getchar();now=0;
    while(Cget>'9'||Cget<'0') Cget=getchar();
    while(Cget>='0'&&Cget<='9') now=now*10+Cget-'0',Cget=getchar();
}

int main()
{
    in(n),in(s);for(ll i=1;i<=n;i++) in(ai[i]);
    ll l=0,r=n,ans=0,ans_=0,mid,pos;
    for(;l<=r;)
    {
        mid=l+r>>1;pos=0;
        for(ll i=1;i<=n;i++) ci[i]=ai[i]+i*mid;
        sort(ci+1,ci+n+1);for(ll i=1;i<=mid;i++) pos+=ci[i];
        if(pos<=s) ans=mid,ans_=pos,l=mid+1;
        else r=mid-1;
    }
    printf("%lld %lld\n",ans,ans_);
    return 0;
}

 

posted @ 2017-06-03 10:32  IIIIIIIIIU  阅读(211)  评论(0编辑  收藏  举报