結果

問題 No.817 Coin donation
ユーザー to10to10to10to
提出日時 2019-04-20 00:11:42
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 702 bytes
コンパイル時間 1,576 ms
コンパイル使用メモリ 167,280 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-24 08:00:24
合計ジャッジ時間 2,600 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 4 WA * 10
権限があれば一括ダウンロードができます

ソースコード

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 += (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