結果

問題 No.817 Coin donation
ユーザー ldsybldsyb
提出日時 2019-04-19 23:53:27
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 537 bytes
コンパイル時間 1,526 ms
コンパイル使用メモリ 168,680 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-09-23 06:38:41
合計ジャッジ時間 2,712 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 14
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main()
{
	int64_t n, k;
	cin >> n >> k;
	vector<pair<int64_t, int64_t>> ps(n);
	for (auto &p : ps)
	{
		cin >> p.first >> p.second;
	}
	auto f = [](vector<pair<int64_t, int64_t>> &ps, int64_t x) {
		int64_t r = 0;
		for (auto &p : ps)
		{
			if (p.first <= x)
			{
				r += min(x, p.second) - p.first + 1;
			}
		}
		return r;
	};
	int64_t l = 0, r = (1LL << 60);
	while (1 < r - l)
	{
		int64_t mid = (l + r) / 2;
		((f(ps, mid) < k) ? l : r) = mid;
	}
	cout << r << endl;
	return 0;
}
0