模拟赛给他们出T1好了~
code:
#include <bits/stdc++.h> #define ll long long #define N 100006 #define setIO(s) freopen(s".in","r",stdin) using namespace std; int n; ll a[N],ck,A[N],S; int check(int tmp) { int i,cnt=0; for(i=1;i<=n;++i) A[i]=a[i]+1ll*tmp*i; sort(A+1,A+1+n); ll pp=0; for(i=1;i<=n;++i) { if(pp+A[i]>S) break; else { pp+=A[i]; ++cnt; if(cnt==tmp) break; } } if(cnt>=tmp) { ck=pp; return 1; } return 0; } int main() { int i,j; // setIO("input"); scanf("%d%lld",&n,&S); for(i=1;i<=n;++i) scanf("%lld",&a[i]); int l=1,r=n,mid,ans=0; for(;l<=r;) { mid=(l+r)>>1; if(check(mid)) ans=mid,l=mid+1; else r=mid-1; } printf("%d %lld ",ans,ck); return 0; }