結果

問題 No.999 てん vs. ほむ
ユーザー KnotsKnots
提出日時 2020-04-27 23:34:13
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 934 bytes
コンパイル時間 1,765 ms
コンパイル使用メモリ 170,708 KB
実行使用メモリ 6,368 KB
最終ジャッジ日時 2024-05-02 04:28:11
合計ジャッジ時間 3,991 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 79 ms
6,288 KB
testcase_10 AC 25 ms
5,376 KB
testcase_11 AC 17 ms
5,376 KB
testcase_12 AC 38 ms
5,376 KB
testcase_13 AC 89 ms
6,360 KB
testcase_14 AC 88 ms
6,364 KB
testcase_15 AC 86 ms
6,364 KB
testcase_16 AC 89 ms
6,368 KB
testcase_17 AC 57 ms
6,140 KB
testcase_18 AC 56 ms
6,164 KB
testcase_19 AC 57 ms
6,176 KB
testcase_20 AC 59 ms
6,180 KB
testcase_21 AC 86 ms
6,352 KB
testcase_22 AC 83 ms
6,204 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