結果

問題 No.817 Coin donation
ユーザー azbrugby
提出日時 2019-05-04 15:35:51
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 84 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 567 ms
コンパイル使用メモリ 67,692 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-22 23:22:48
合計ジャッジ時間 1,953 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <climits>
#define scanf scanf_s
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007,N=100010;

ll n, k;
pos ab[N];

bool ok(ll v1) {
	ll kv = 0;
	for (int i = 1; i <= n; i++) {
		ll vv1 = ab[i].first, vv2 = ab[i].second;
		kv += max((ll)0, min(v1, vv2) - vv1 + 1);

	}
	return kv >= k;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)cin >> ab[i].first >> ab[i].second;
	ll mnv = 0, mxv = 1000000010;
	while (mxv - mnv > 1) {
		ll md = (mxv + mnv) / 2;
		if (ok(md))mxv = md;
		else mnv = md;
	}
	cout << mxv << endl;
	return 0;
}

0