結果

問題 No.904 サメトロ
ユーザー cotton_fn_
提出日時 2019-12-12 15:32:37
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 3 ms / 1,000 ms
コード長 692 bytes
コンパイル時間 1,055 ms
コンパイル使用メモリ 99,304 KB
最終ジャッジ日時 2025-01-08 10:56:21
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <utility>
#include <tuple>
#include <string>
#include <cstdint>
#include <vector>
#include <array>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <cassert>
using namespace std;
using i64 = int64_t;
i64 n;
vector<int> a, b;
int main() {
    cin >> n;
    a.resize(n);
    b.resize(n);
    i64 sa = 0, sb = 0;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a[i] >> b[i];
        sa += a[i];
        sb += b[i];
    }
    i64 x = 0;
    for (int i = 0; i < n - 1; ++i) {
        x = max(x, min(sa, sb) - (sa - a[i]) - (sb - b[i]));
    }
    i64 ans = min(sa, sb) + 1;
    cout << ans - x << endl;
    return 0;
}
0