結果
問題 | No.999 てん vs. ほむ |
ユーザー |
![]() |
提出日時 | 2020-05-03 14:19:45 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 83 ms / 2,000 ms |
コード長 | 824 bytes |
コンパイル時間 | 1,920 ms |
コンパイル使用メモリ | 166,900 KB |
実行使用メモリ | 6,656 KB |
最終ジャッジ日時 | 2024-06-12 01:22:46 |
合計ジャッジ時間 | 4,698 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ll n; cin >> n; n *= 2; ll a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } ll sum = 0; for (int i = 0; i < n; i++) { sum += a[i]; } ll sumL[n/2]; ll sumR[n/2]; memset(sumL, 0, sizeof(sumL)); memset(sumR, 0, sizeof(sumR)); sumL[0] = a[0]; for (int i = 2; i < n; i+=2) { sumL[i/2] = a[i] + sumL[i/2-1]; } sumR[n/2-1] = a[n-1]; for (int i = n-3; i >= 0; i-=2) { sumR[i/2] = a[i] + sumR[i/2+1]; } ll ans = max(sumL[n/2-1]-sumR[0], sumR[0]-sumL[n/2-1]); for (int i = 0; i < n/2-1; i++) { ans = max(ans, 2*(sumL[i]+sumR[i+1])-sum); } cout << ans << endl; return 0; }