結果

問題 No.904 サメトロ
ユーザー 👑 CleyL
提出日時 2019-10-11 23:01:20
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 758 bytes
コンパイル時間 638 ms
コンパイル使用メモリ 79,652 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-11-25 09:07:00
合計ジャッジ時間 1,551 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
using namespace std;
typedef pair<int,int> Paint;
bool pairSum(const Paint& pf,Paint&ps){//sortCompare
  return pf.first+pf.second > ps.first+ps.second;
}
int main(){
  int n;cin>>n;
  if(n==2){
    cout << 1 << endl;
    return 0;
  }
  vector<Paint> a(n-1);
  int a_sm = 0;
  int b_sm = 0;
  for(int i = 0; n-1 > i; i++){
    cin>>a[i].first>>a[i].second;
    a_sm += a[i].first;
    b_sm += a[i].second;
  }
  sort(a.begin(),a.end(),pairSum);
  for(int i = 1; n-1 > i; i++){
    a[0].first -= a[i].second;
    a[0].second -= a[i].first;
  }
  if(a[0].first <= 0 || a[0].second <= 0){
    cout << min(a_sm,b_sm)+1 << endl;
  }else{
    cout << a_sm - a[0].first + 1 << endl;
  }
}
0