結果
問題 | No.999 てん vs. ほむ |
ユーザー |
|
提出日時 | 2020-04-09 01:04:20 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 22 ms / 2,000 ms |
コード長 | 784 bytes |
コンパイル時間 | 1,479 ms |
コンパイル使用メモリ | 168,916 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-07-19 05:57:50 |
合計ジャッジ時間 | 2,599 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 20 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> P; #define rep(i, n) for (int i = 0; i < (int)(n); ++i) #define all(x) (x).begin(),(x).end() template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;} template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;} int main(){ cin.tie(0); ios::sync_with_stdio(false); ll n;cin>>n; vector<pair<ll,ll>> a(n); ll sum=0; rep(i, n){ ll p,q;cin>>p>>q; a[i] = make_pair(p,q); sum+=(p-q); } ll ans = sum; for(int i=n-1;i>=0;i--){ pair<ll,ll> p = a[i]; sum = sum-(p.first-p.second)+(p.second-p.first); ans = max(ans, sum); } cout<<ans<<endl; }