結果

問題 No.817 Coin donation
ユーザー azbrugbyazbrugby
提出日時 2019-05-04 15:35:51
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 730 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 68,516 KB
実行使用メモリ 5,088 KB
最終ジャッジ日時 2023-09-05 02:32:47
合計ジャッジ時間 1,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 3 ms
4,384 KB
testcase_06 AC 11 ms
4,380 KB
testcase_07 AC 15 ms
4,376 KB
testcase_08 AC 56 ms
4,440 KB
testcase_09 AC 17 ms
4,376 KB
testcase_10 AC 79 ms
5,088 KB
testcase_11 AC 79 ms
4,928 KB
testcase_12 AC 79 ms
4,936 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

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