Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<cstdio>
- #include<algorithm>
- #define MAX_N 1000010
- using namespace std;
- int n,t;
- long long a[MAX_N];
- long long qs[MAX_N];
- long long ans;
- int main()
- {
- scanf("%d%d",&n,&t);
- for(int c=1;c<=n;c++) scanf("%lld",&a[c]);
- for(int c=1;c<=n;c++) qs[c] = qs[c-1] + a[c];
- if( n == 1 )
- {
- printf("%lld\n",a[1]*(t/2+1));
- return 0;
- }
- for(int c=2;c<=n and c<=t+1;c++)
- {
- long long tmp = qs[c];
- int rem = t+1-c;
- tmp += ((rem+1)/2)*a[c-1];
- tmp += (rem/2)*a[c];
- ans = max( ans , tmp );
- }
- printf("%lld\n",ans);
- }
Advertisement
Add Comment
Please, Sign In to add comment