提交时间:2023-12-17 13:55:16

运行 ID: 222891

#include <iostream> #include <algorithm> #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]; } sort(a + 1,a + n + 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]); } cout << ans; }