Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market
Two-point answer + sort
Test instructions has a[I] number requires the most selected number so that it and not more than S, and in this case, and the minimum
Select most of the cases and the smallest and each number has a bonus
If the number of K is selected then the addition is a[I] + k*i;
The two-point mid indicates the selected number
Add a bit, will be added after the results sorted, if the previous mid number and greater than the scheme is not feasible
PS to use a long long ..... and codeforces to use%I64D.
1#include <cstdio>2#include <cstring>3#include <iomanip>4#include <algorithm>5 #definell Long Long6 using namespacestd;7 8 Constll MAXN =100011 ; 9 ll N,s,l,r,mid;Ten ll A[MAXN],B[MAXN]; One AInlineBOOLCheck (ll mid) - { -ll sum =0 ; the for(LL i=1; i<=n;i++) b[i] = a[i] + 1ll*i*mid; -Sort (b +1, b+n+1) ; - for(LL i=1; i<=mid;i++) -sum+=b[i]; + returnSum <=s; - } + A intMain () at { -scanf"%i64d%i64d",&n,&s); - for(LL i=1; i<=n;i++) scanf ("%i64d", &a[i]), b[i] =a[i]; -Sort (b +1, b+n+1) ; -L =0; R =N; - while(l<R) in { -Mid = (l+r+1) >>1 ; to if(Check (mid)) L =mid; + ElseR = Mid-1 ; - } theprintf"%i64d", L); *ll sum =0 ; $ for(LL i=1; i<=n;i++) b[i] = a[i] + 1ll*i*l;Panax NotoginsengSort (b +1, b+n+1) ; - for(LL i=1; i<= l; i++) thesum+=b[i]; +printf"%i64d\n", sum); A return 0 ; the}
Codeforces Round #417 (Div. 2) C. Sagheer and Nubian market Two-point answer + sort