結果

問題 No.817 Coin donation
ユーザー misora192misora192
提出日時 2020-06-23 09:21:25
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 189 ms / 2,000 ms
コード長 846 bytes
コンパイル時間 1,588 ms
コンパイル使用メモリ 172,104 KB
実行使用メモリ 16,048 KB
最終ジャッジ日時 2023-09-16 19:47:37
合計ジャッジ時間 3,283 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,384 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 17 ms
4,996 KB
testcase_07 AC 22 ms
5,640 KB
testcase_08 AC 119 ms
11,960 KB
testcase_09 AC 27 ms
5,864 KB
testcase_10 AC 186 ms
16,048 KB
testcase_11 AC 189 ms
15,960 KB
testcase_12 AC 187 ms
15,940 KB
testcase_13 AC 1 ms
4,380 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);

	ll n, k;
	cin >> n >> k;

	map<ll, ll> mp;
	rep(i, n){
		ll a, b;
		cin >> a >> b;
		b++;
		if(mp.count(a) == 0) mp[a] = 0;
		mp[a]++;
		if(mp.count(b) == 0) mp[b] = 0;
		mp[b]--;
	}

	ll sm = 0;
	ll t = 0;
	ll x = 0;
	for(auto p : mp){
		ll y = p.first;
		ll z = p.second;
		if(sm + (y - x - 1) * t >= k){
			cout << x + (k - sm + t - 1) / t << endl;
			exit(0);
		}

		sm += (y - x - 1) * t;
		if(sm + (t + z) >= k){
			cout << y << endl;
			exit(0);
		}

		sm += t + z;
		x = y;
		t += z;
	}
}
0