結果

問題 No.817 Coin donation
ユーザー tomatoma
提出日時 2019-04-19 21:41:56
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 1,871 ms
コンパイル使用メモリ 173,952 KB
実行使用メモリ 4,912 KB
最終ジャッジ日時 2023-10-24 00:49:20
合計ジャッジ時間 3,145 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 14 ms
4,348 KB
testcase_07 AC 17 ms
4,348 KB
testcase_08 AC 65 ms
4,384 KB
testcase_09 AC 20 ms
4,348 KB
testcase_10 AC 94 ms
4,912 KB
testcase_11 AC 93 ms
4,912 KB
testcase_12 AC 93 ms
4,912 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"bits/stdc++.h"

using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define FOR(k,m,n) for(ll (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<< #str << " " str<<endl

constexpr int INF = (1 << 30);
constexpr ll INFL = (1ll << 60);
constexpr ll MOD = 1000000007;// 10^9+7



int main()
{
	ll N, K;
	cin >> N >> K;
	vector<pair<ll, ll>> abs(N);
	REP(i, N) {
		ll a, b;
		cin >> a >> b;
		abs[i] = { a,b };
	}
	sort(abs.begin(), abs.end());

	ll l = 0, r = 1e9 + 10;
	while (r - l > 1) {
		ll mid = (l + r) / 2;
		ll num = 0;
		for (auto ab : abs) {
			ll a = ab.first;
			ll b = ab.second;
			if (mid < a)continue;
			if (b < mid) {
				num += (b - a + 1);
			}
			else {
				num += (mid - a + 1);
			}
		}
		if (num < K)l = mid;
		else r = mid;
	}
	cout << r << endl;
	return 0;
}
0