Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define task "PRODSUM"
- #include <iostream>
- #include <cstdio>
- using namespace std;
- using ll = long long;
- using ld = long double;
- constexpr int N = 2e5 + 5;
- int n, a[N];
- ll C, b[N], Cl[N], Cr[N];
- void Read()
- {
- cin >> n;
- for (int i = 1; i <= n; ++i)
- {
- cin >> a[i];
- C += 1ll * i * a[i];
- b[i] = b[i - 1] + a[i];
- }
- }
- void Solve()
- {
- ll ans = C;
- for (int i = 1; i <= n; ++i)
- {
- Cl[i] = C + b[i - 1] - 1ll * (i - 1) * a[i];
- Cr[i] = C - (b[n] - b[i]) + 1ll * (n - i) * a[i];
- ans = max(ans, max(Cl[i], Cr[i]));
- }
- cout << ans;
- }
- int32_t main()
- {
- ios::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- if (fopen(task ".INP", "r"))
- {
- freopen(task ".INP", "r", stdin);
- freopen(task ".OUT", "w", stdout);
- }
- Read();
- Solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement