結果

問題 No.817 Coin donation
ユーザー aa
提出日時 2019-04-19 21:44:56
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 500 bytes
コンパイル時間 1,370 ms
使用メモリ 4,756 KB
最終ジャッジ日時 2022-11-22 08:12:36
合計ジャッジ時間 2,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,532 KB
testcase_01 AC 2 ms
3,532 KB
testcase_02 AC 1 ms
3,536 KB
testcase_03 AC 2 ms
3,432 KB
testcase_04 AC 1 ms
3,484 KB
testcase_05 AC 3 ms
3,424 KB
testcase_06 AC 11 ms
3,688 KB
testcase_07 AC 14 ms
3,428 KB
testcase_08 AC 53 ms
4,144 KB
testcase_09 AC 17 ms
3,620 KB
testcase_10 AC 76 ms
4,624 KB
testcase_11 AC 77 ms
4,756 KB
testcase_12 AC 77 ms
4,676 KB
testcase_13 AC 1 ms
3,496 KB
testcase_14 AC 2 ms
3,440 KB
testcase_15 AC 2 ms
3,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"

using namespace std;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<long> as(n), bs(n);
	for (int i = 0; i < n; i++)
	{
		cin >> as[i] >> bs[i];
	}
	int ng = 0, ok = 1e9;
	while(ng+1<ok)
	{
		int x = (ok + ng) / 2;
		long res = 0;
		for (int i = 0; i < n; i++)
		{
			if (as[i] > x) continue;
			res += min(bs[i] - as[i], x - as[i]) + 1;
		}
		(res >= k ? ok : ng) = x;
	}
	cout << ok << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}
0