結果

問題 No.999 てん vs. ほむ
ユーザー KnotsKnots
提出日時 2020-04-27 23:34:13
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 76 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 1,470 ms
コンパイル使用メモリ 169,796 KB
実行使用メモリ 6,456 KB
最終ジャッジ日時 2023-08-14 16:22:27
合計ジャッジ時間 4,347 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 1 ms
4,376 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 68 ms
6,024 KB
testcase_10 AC 22 ms
4,380 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 32 ms
4,448 KB
testcase_13 AC 75 ms
6,456 KB
testcase_14 AC 75 ms
6,300 KB
testcase_15 AC 75 ms
6,096 KB
testcase_16 AC 76 ms
6,100 KB
testcase_17 AC 50 ms
6,216 KB
testcase_18 AC 51 ms
6,072 KB
testcase_19 AC 52 ms
6,144 KB
testcase_20 AC 51 ms
6,040 KB
testcase_21 AC 75 ms
6,084 KB
testcase_22 AC 74 ms
6,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n;
    cin >> n;
    vector<int> vec(2*n);
    ll ans = -LINF;
    
    REP(i,2*n)cin >> vec[i];
    
    vector<ll> right;
    right.push_back(0);
    vector<ll> left;
    left.push_back(0);
    
    ll ans1 = 0,ans2 = 0;
    
    for(int i=0;i<2*n-1;i+=2){
        ans1 += vec[i]-vec[i+1];
        right.push_back(ans1);//右側からの累積和
    }
    for(int i=2*n-1;i>0;i-=2){
        ans2 += vec[i]-vec[i-1];
        left.push_back(ans2);//左側からの累積和
    }
    
    REP(i,n+1){
        ans = max(right[i]+left[n-i],ans);
    }
    
    COUT(ans);
    return 0;
}
0