模拟赛给他们出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\n",ans,ck); return 0; }
原文地址:https://www.cnblogs.com/guangheli/p/11620020.html
时间: 2024-10-08 20:22:37