結果

問題 No.999 てん vs. ほむ
ユーザー srtubakisrtubaki
提出日時 2020-02-28 22:58:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 2,546 bytes
コンパイル時間 2,546 ms
コンパイル使用メモリ 168,748 KB
実行使用メモリ 6,212 KB
最終ジャッジ日時 2023-08-03 21:40:34
合計ジャッジ時間 3,026 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 25 ms
5,824 KB
testcase_10 AC 8 ms
4,376 KB
testcase_11 AC 6 ms
4,380 KB
testcase_12 AC 12 ms
4,384 KB
testcase_13 AC 28 ms
6,120 KB
testcase_14 AC 27 ms
6,124 KB
testcase_15 AC 28 ms
6,212 KB
testcase_16 AC 28 ms
6,164 KB
testcase_17 AC 20 ms
5,948 KB
testcase_18 AC 20 ms
5,880 KB
testcase_19 AC 20 ms
5,900 KB
testcase_20 AC 20 ms
5,824 KB
testcase_21 AC 27 ms
6,212 KB
testcase_22 AC 26 ms
5,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region template

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

// -type-
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using vpii = vector<pii>;
using vpll = vector<pll>;


// -const-
const ll MOD = 1000000007;

const ll INF = (ll)0x3f0000003f000000;
const double EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1},
          dy[] = {1, 0, -1, 0, 1, -1, -1, 1};


// -define-
#define reps(i, k, n) for (int i = (k), i##_len = (n); i < i##_len; ++i)
#define rep(i, n) reps(i, 0, n)
#define repsr(i, k, n) \
    for (int i = int(n) - 1, i##_len = (k); i >= i##_len; --i)
#define repr(i, n) for (int i = int(n) - 1; i >= 0; --i)
#define all(o) begin(o), end(o)
#define sz(a) ((int)(a).size())
#define debug(...) debug_args(__LINE__, __VA_ARGS__)


// clang-format off
// -functions-
inline bool in(string s, string c) {return (s.find(c) != string::npos);}
inline bool in(string s,   char c) {return (s.find(c) != string::npos);}

template <class T> T udiv(T a, T b) {return (a + b - 1) / b;}
template <class T> T rdiv(T a, T b) {return (a + b / 2) / b;}

void print_args(ostream&) {}
template <class S, class... T>
void print_args(ostream& out,const S& a,const T&... args) {
    out << ' ' << a;
    print_args(out, args...);
}
template <class S, class... T>
void print(const S& a, const T&... args) {
    std::cout << a;
    print_args(std::cout, args...);
    std::cout << '\n';
}
template <class S, class... T>
void debug_args(const S& a, const T&... args) {
    std::cout << "(L:" << std::setw(3) << a << ")";
    print_args(std::cout, args...);
    std::cout << '\n';
}
// clang-format on

struct setup_main {
    setup_main() {
        std::cin.tie(0);
        std::ios::sync_with_stdio(0);
        std::cout << fixed << setprecision(15);
    }
} setup_main_;

ll ans = 0;
#pragma endregion

bool st(true), en(false);

int main() {
    int n;
    cin >> n;
    vpll a(n + 1, make_pair(0, 0));
    vl rsum(n + 2, 0);
    vl lsum(n + 2, 0);
    reps(i, 1, n + 1) {
        cin >> a[i].first;
        cin >> a[i].second;
    }
    reps(i, 1, n + 1) {
        lsum[i] += a[i].first - a[i].second;
    }
    reps(i, 1, n + 1) lsum[i + 1] += lsum[i];

    reps(i, 1, n + 1) {
        rsum[i - 1] = a[i].second - a[i].first;
    }
    for (int i = n - 1; i > 0; i--) rsum[i - 1] += rsum[i];

    rep(i, n + 1) {
        ans = max<ll>(ans, lsum[i] + rsum[i]);
    }

    print(ans);
}
0