Dang_Quan_10_Tin

PRODSUM HSGVinh Phuc L9 2015-2016

Jan 15th, 2022
802
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define task "PRODSUM"
  2.  
  3. #include <iostream>
  4. #include <cstdio>
  5.  
  6. using namespace std;
  7.  
  8. using ll = long long;
  9. using ld = long double;
  10.  
  11. constexpr int N = 2e5 + 5;
  12. int n, a[N];
  13. ll C, b[N], Cl[N], Cr[N];
  14.  
  15. void Read()
  16. {
  17.     cin >> n;
  18.  
  19.     for (int i = 1; i <= n; ++i)
  20.     {
  21.         cin >> a[i];
  22.         C += 1ll * i * a[i];
  23.         b[i] = b[i - 1] + a[i];
  24.     }
  25. }
  26.  
  27. void Solve()
  28. {
  29.     ll ans = C;
  30.  
  31.     for (int i = 1; i <= n; ++i)
  32.     {
  33.         Cl[i] = C + b[i - 1] - 1ll * (i - 1) * a[i];
  34.         Cr[i] = C - (b[n] - b[i]) + 1ll * (n - i) * a[i];
  35.  
  36.         ans = max(ans, max(Cl[i], Cr[i]));
  37.     }
  38.  
  39.     cout << ans;
  40. }
  41.  
  42. int32_t main()
  43. {
  44.     ios::sync_with_stdio(0);
  45.     cin.tie(0);
  46.     cout.tie(0);
  47.     if (fopen(task ".INP", "r"))
  48.     {
  49.         freopen(task ".INP", "r", stdin);
  50.         freopen(task ".OUT", "w", stdout);
  51.     }
  52.     Read();
  53.     Solve();
  54. }
  55.  
RAW Paste Data