結果

問題 No.817 Coin donation
ユーザー leaf_1415leaf_1415
提出日時 2019-04-19 21:34:46
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 487 bytes
コンパイル時間 538 ms
コンパイル使用メモリ 55,876 KB
実行使用メモリ 5,216 KB
最終ジャッジ日時 2023-10-23 23:49:42
合計ジャッジ時間 1,909 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 59 ms
4,736 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 85 ms
5,216 KB
testcase_11 AC 85 ms
5,216 KB
testcase_12 AC 85 ms
5,216 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 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