Advertisement
erek1e

POI Task Mushrooms [B]

Jul 1st, 2023
935
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.57 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  8.     int n, t;
  9.     cin >> n >> t;
  10.     long long mx = 0, prefixSum = 0;
  11.     int previous = 0;
  12.     for (int i = 1; i <= n; ++i) {
  13.         int current; cin >> current;
  14.         int movesLeft = t-i+2;
  15.         if (movesLeft <= 0) break;
  16.         mx = max(mx, prefixSum + ((movesLeft/2)+1LL)*previous + ((movesLeft+1LL)/2)*current);
  17.         prefixSum += previous;
  18.         previous = current;
  19.     }
  20.     cout << mx << endl;
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement