提交时间:2024-12-12 17:05:20
运行 ID: 314164
#include <iostream> #define int __int128 using namespace std; int n; int cnt[100005], a[100005]; istream& operator>>(istream& in, int &x) { long long y; in >> y; x = y; return in; } ostream& operator<<(ostream& out, int x) { string s; while (x) { s = char(x % 10 ^ 48) + s; x /= 10; } out << s; return out; } signed main() { cin >> n; for (int i = 1; i <= n; i++) { cin >> a[i]; cnt[i] = a[i] + cnt[i - 1]; } int ans(cnt[n]); for (int i = 1; i < n; i++) { ans = max(ans, cnt[n] - a[i] - a[i + 1] + a[i] * a[i + 1]); } ans = max(ans, cnt[n] - a[1] - a[n] + a[1] * a[n]); cout << ans; }