Guest User

Untitled

a guest
Jun 28th, 2013
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include<cstdio>
  2. #include<algorithm>
  3. #define MAX_N 1000010
  4. using namespace std;
  5.  
  6. int n,t;
  7. long long a[MAX_N];
  8. long long qs[MAX_N];
  9. long long ans;
  10.  
  11. int main()
  12. {
  13.     scanf("%d%d",&n,&t);
  14.     for(int c=1;c<=n;c++) scanf("%lld",&a[c]);
  15.     for(int c=1;c<=n;c++) qs[c] = qs[c-1] + a[c];
  16.    
  17.     if( n == 1 )
  18.     {
  19.         printf("%lld\n",a[1]*(t/2+1));
  20.         return 0;
  21.     }
  22.    
  23.     for(int c=2;c<=n and c<=t+1;c++)
  24.     {
  25.         long long tmp = qs[c];
  26.         int rem = t+1-c;
  27.         tmp += ((rem+1)/2)*a[c-1];
  28.         tmp += (rem/2)*a[c];
  29.         ans = max( ans , tmp );
  30.     }
  31.     printf("%lld\n",ans);
  32. }
Advertisement
Add Comment
Please, Sign In to add comment