結果

問題 No.999 てん vs. ほむ
ユーザー ui_mtcui_mtc
提出日時 2020-03-30 17:10:08
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 984 bytes
コンパイル時間 1,552 ms
コンパイル使用メモリ 167,752 KB
実行使用メモリ 6,324 KB
最終ジャッジ日時 2023-09-03 22:48:57
合計ジャッジ時間 4,565 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 1 ms
4,384 KB
testcase_08 AC 4 ms
4,380 KB
testcase_09 AC 71 ms
5,912 KB
testcase_10 AC 22 ms
4,384 KB
testcase_11 AC 16 ms
4,376 KB
testcase_12 AC 32 ms
4,624 KB
testcase_13 AC 78 ms
6,192 KB
testcase_14 AC 78 ms
6,324 KB
testcase_15 AC 78 ms
6,264 KB
testcase_16 AC 78 ms
6,132 KB
testcase_17 AC 51 ms
5,948 KB
testcase_18 AC 50 ms
5,892 KB
testcase_19 AC 51 ms
6,044 KB
testcase_20 AC 52 ms
5,932 KB
testcase_21 AC 76 ms
6,188 KB
testcase_22 AC 75 ms
5,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define int long long 
using namespace std;
using Graph = vector<vector<int>>;

signed main(){
  int N;
  cin >> N;
  vector<int> A(2*N);
  for( int i = 0; i < 2*N; i++ ) cin >> A.at(i);
  
  vector<int> right(N);
  vector<int> left(N);
  for( int i = 0; i < N; i++ ){
    left.at(i) = A.at(i*2)-A.at(i*2+1);
    if( i > 0 ) left.at(i) += left.at(i-1);
  }
  reverse(A.begin(), A.end());
  for( int i = 0; i < N; i++ ){
    right.at(i) = A.at(i*2)-A.at(i*2+1);
    if( i > 0 ) right.at(i) += right.at(i-1);
  }
  reverse(right.begin(), right.end());
  
  /* for( int i = 0; i < N; i++ ) cout << left.at(i) << " ";
  cout << endl;
  for( int i = 0; i < N; i++ ) cout << right.at(i) << " ";
  cout << endl; */
  
  //全部右からとった場合、全部左からとった場合
  int ans = max(left.at(N-1), right.at(0));
  
  for( int i = 0; i < N-1; i++ ){
    int now = left.at(i)+right.at(i+1);
    ans = max(ans, now);
  }
  cout << ans << endl;
    
}
0