結果

問題 No.817 Coin donation
ユーザー ransewhaleransewhale
提出日時 2019-04-19 21:46:35
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 125 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 1,569 ms
使用メモリ 7,708 KB
最終ジャッジ日時 2022-11-22 08:17:29
合計ジャッジ時間 3,199 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,364 KB
testcase_01 AC 1 ms
3,448 KB
testcase_02 AC 2 ms
3,448 KB
testcase_03 AC 2 ms
3,404 KB
testcase_04 AC 2 ms
3,364 KB
testcase_05 AC 4 ms
3,616 KB
testcase_06 AC 16 ms
3,892 KB
testcase_07 AC 20 ms
4,112 KB
testcase_08 AC 84 ms
6,364 KB
testcase_09 AC 23 ms
4,180 KB
testcase_10 AC 122 ms
7,692 KB
testcase_11 AC 125 ms
7,680 KB
testcase_12 AC 124 ms
7,708 KB
testcase_13 AC 2 ms
3,492 KB
testcase_14 AC 1 ms
3,484 KB
testcase_15 AC 1 ms
3,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<30)
typedef pair<int, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a += b;
	a %= MOD;
}
ll cnt[225816],a[100100],b[100100];
vector<ll> v;

int main(void){
	int n,m,i;
	ll k;
	cin >> n >> k;
	--k;
	for(i=0; i<n; ++i){
		cin >> a[i] >> b[i];
		++b[i];
		v.push_back(a[i]);
		v.push_back(b[i]);
	}
	v.push_back(INFLL);
	sort(v.begin(),v.end());
	for(i=0; i<n; ++i){
		++cnt[(int)(lower_bound(v.begin(),v.end(),a[i])-v.begin())];
		--cnt[(int)(lower_bound(v.begin(),v.end(),b[i])-v.begin())];
	}
	m = v.l_ength()-1;
	for(i=0; i<m; ++i){
		cnt[i+1] += cnt[i];
	}
	for(i=0; i<m; ++i){
		if(v[i]==v[i+1]){
			continue;
		}
		if(0<=k && k<cnt[i]*(v[i+1]-v[i])){
			cout << (v[i]+k/cnt[i]) << endl;
			break;
		}
		k -= cnt[i]*(v[i+1]-v[i]);
	}
	return 0;
}
0