結果

問題 No.817 Coin donation
ユーザー to10to10to10toto10to10to10to
提出日時 2019-04-20 00:13:07
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 83 ms / 2,000 ms
コード長 713 bytes
コンパイル時間 1,396 ms
コンパイル使用メモリ 167,116 KB
実行使用メモリ 5,196 KB
最終ジャッジ日時 2023-10-24 16:41:46
合計ジャッジ時間 2,446 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 12 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 57 ms
4,716 KB
testcase_09 AC 18 ms
4,348 KB
testcase_10 AC 82 ms
5,196 KB
testcase_11 AC 82 ms
5,196 KB
testcase_12 AC 83 ms
5,196 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#define reps(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   reps(i,0,n)
#define all(x) (x).begin(),(x).end()
#define INF (1000000000)
#define MOD (1000000007)
#define PI (acos(-1))

ll N,K;
ll A[100010],B[100010];
bool isOK(ll x){//x円以下のコインがk枚以上存在するか
  ll cnt=0;
  rep(i,N){
    cnt += max((ll)0,(min(B[i],x)-A[i])+1);
    if(cnt >= K)return true;
  }
  return false;
}

int main(){
  cin >> N >> K;
  rep(i,N){
    cin >> A[i] >> B[i];
  }

  ll ok = 1e18, ng = 0;
  while(abs(ok-ng)>1){
    ll mid = (ok+ng)/2;
    if(isOK(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << ok << endl;
}
0