結果

問題 No.999 てん vs. ほむ
ユーザー horoyoisawahoroyoisawa
提出日時 2020-02-29 21:00:19
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 1,880 bytes
コンパイル時間 1,622 ms
コンパイル使用メモリ 167,512 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-21 21:54:55
合計ジャッジ時間 3,502 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,940 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 77 ms
6,940 KB
testcase_10 AC 24 ms
6,944 KB
testcase_11 AC 17 ms
6,944 KB
testcase_12 AC 36 ms
6,940 KB
testcase_13 AC 85 ms
6,940 KB
testcase_14 AC 85 ms
6,944 KB
testcase_15 AC 85 ms
6,944 KB
testcase_16 AC 85 ms
6,944 KB
testcase_17 AC 55 ms
6,944 KB
testcase_18 AC 54 ms
6,944 KB
testcase_19 AC 55 ms
6,940 KB
testcase_20 AC 55 ms
6,940 KB
testcase_21 AC 84 ms
6,944 KB
testcase_22 AC 80 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

const int MAX = 200005;
const long long MOD = 1000000007;
const long long MODMOD = 998244353;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

long long gcd(long long a, long long b) {
  if(a % b == 0) return b;
  else return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  vector<ll> a(2 * n);
  ll homura = 0, tempura = 0;
  rep(i, 2 * n) {
    cin >> a[i];
    if(i % 2 == 0) tempura += a[i];
    else homura += a[i];
  }
  long long ans = homura - tempura;
  for(int i=0;i<2*n-1;i+=2) {
    homura = homura - a[i+1] + a[i];
    tempura = tempura - a[i] + a[i+1];
    chmax(ans, homura - tempura);
  }
  cout << ans << endl;
}
0