結果

問題 No.999 てん vs. ほむ
ユーザー rjkurorjkuro
提出日時 2020-02-29 06:59:59
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,577 bytes
コンパイル時間 1,421 ms
コンパイル使用メモリ 110,848 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-21 21:26:48
合計ジャッジ時間 3,300 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 3 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 5 ms
5,376 KB
testcase_09 AC 78 ms
5,376 KB
testcase_10 AC 25 ms
5,376 KB
testcase_11 AC 18 ms
5,376 KB
testcase_12 AC 37 ms
5,376 KB
testcase_13 AC 85 ms
5,376 KB
testcase_14 AC 85 ms
5,376 KB
testcase_15 AC 84 ms
5,376 KB
testcase_16 AC 85 ms
5,376 KB
testcase_17 AC 56 ms
5,376 KB
testcase_18 AC 55 ms
5,376 KB
testcase_19 AC 55 ms
5,376 KB
testcase_20 AC 56 ms
5,376 KB
testcase_21 AC 83 ms
5,376 KB
testcase_22 AC 81 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <cassert>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)
#define RRANGE(i, m, n) for(ll i = (m); i >= (n); --i)
#define POSITIVE(x) (x)=((x) < 0) ? 0 : (x)

ll power(ll x, ll y) {
    ll ret = 1;
    while(y-- > 0) ret *= x;
    return ret;
}

ll gcd(ll a, ll b) {
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll iabs(ll x) {
    return x < 0 ? -x : x;
}

ll extgcd(ll a, ll b, ll& x, ll& y) {
    x = 1; y = 0;
    assert(a >= 0);
    assert(b >= 0);
    if (b == 0) return a;
    ll X, Y;
    auto d = extgcd(b, a % b, X, Y);
    x = Y;
    y = X - (a / b) * Y;
    return d;
}

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    vector<ll> v(2*N);
    ll a=0, b = 0;
    REP(i, N) {
        in >> v[2*i];
        in >> v[2*i+1];
        a+= v[2*i];
        b+= v[2*i+1];
    }
    ll total = a - b;
    ll ans = total;
    RRANGE(i, N-1, 0) {
        total -= 2*(v[2*i] - v[2*i+1]);
        ans = max(ans, total);
    }
    out << ans << endl;
    return 0;
}


int main() {
    return run(cin, cout);
}
0