結果

問題 No.817 Coin donation
ユーザー leaf_1415leaf_1415
提出日時 2019-04-19 21:34:46
言語 C++11
(gcc 8.5.0)
結果
AC  
実行時間 77 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 319 ms
使用メモリ 4,984 KB
最終ジャッジ日時 2022-11-22 06:35:33
合計ジャッジ時間 1,800 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,484 KB
testcase_01 AC 1 ms
3,436 KB
testcase_02 AC 2 ms
3,404 KB
testcase_03 AC 1 ms
3,432 KB
testcase_04 AC 2 ms
3,424 KB
testcase_05 AC 3 ms
3,400 KB
testcase_06 AC 12 ms
3,576 KB
testcase_07 AC 14 ms
3,724 KB
testcase_08 AC 53 ms
4,536 KB
testcase_09 AC 16 ms
3,740 KB
testcase_10 AC 77 ms
4,924 KB
testcase_11 AC 75 ms
4,984 KB
testcase_12 AC 75 ms
4,928 KB
testcase_13 AC 1 ms
3,376 KB
testcase_14 AC 1 ms
3,424 KB
testcase_15 AC 1 ms
3,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#define llint long long

using namespace std;

llint n, k;
llint a[100005], b[100005];

bool check(llint x)
{
	llint cnt = 0;
	for(int i = 1; i <= n; i++){
		cnt += min(b[i]-a[i]+1, max(0LL, x-a[i]+1));
	}
	return cnt >= k;
}

int main(void)
{
	cin >> n >> k;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i];
	
	llint ub = 1000000000, lb = 0, mid;
	while(ub-lb>1){
		mid = (ub+lb)/2;
		if(check(mid)) ub = mid;
		else lb = mid;
	}
	cout << ub << endl;
	
	return 0;
}
0