結果

問題 No.999 てん vs. ほむ
ユーザー hiro71687khiro71687k
提出日時 2023-08-26 23:59:49
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 78 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 4,782 ms
コンパイル使用メモリ 259,376 KB
実行使用メモリ 5,516 KB
最終ジャッジ日時 2023-08-26 23:59:57
合計ジャッジ時間 6,896 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 4 ms
4,376 KB
testcase_09 AC 70 ms
5,168 KB
testcase_10 AC 22 ms
4,376 KB
testcase_11 AC 15 ms
4,376 KB
testcase_12 AC 32 ms
4,376 KB
testcase_13 AC 78 ms
5,516 KB
testcase_14 AC 76 ms
5,420 KB
testcase_15 AC 77 ms
5,380 KB
testcase_16 AC 77 ms
5,448 KB
testcase_17 AC 51 ms
5,148 KB
testcase_18 AC 50 ms
5,408 KB
testcase_19 AC 50 ms
5,160 KB
testcase_20 AC 51 ms
5,176 KB
testcase_21 AC 75 ms
5,452 KB
testcase_22 AC 74 ms
5,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll mod=998244353;
ll inf=1009999999999999990;
int main(){
    ll n;
    cin >> n;
    vector<ll>a(2*n);
    for (ll i = 0; i < n*2; i++)
    {
        cin >> a[i];
    }
    vector<ll>b(n);
    for (ll i = 0; i < n; i++)
    {
        b[i]=a[i*2+1]-a[i*2];
        if (i>0)
        {
            b[i]+=b[i-1];
        }
    }
    ll ans=b[n-1];
    ll now=b[n-1];
    for (ll i = 0; i < n; i++)
    {
        now+=(a[i*2]-a[i*2+1])*2;
        ans=max(ans,now);
    }
    cout << ans << endl;
}
0