結果

問題 No.817 Coin donation
ユーザー ransewhaleransewhale
提出日時 2019-04-19 21:46:35
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 132 ms / 2,000 ms
コード長 971 bytes
コンパイル時間 2,053 ms
コンパイル使用メモリ 174,236 KB
実行使用メモリ 8,248 KB
最終ジャッジ日時 2023-10-24 01:13:24
合計ジャッジ時間 3,155 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,748 KB
testcase_01 AC 2 ms
5,752 KB
testcase_02 AC 3 ms
5,752 KB
testcase_03 AC 3 ms
5,756 KB
testcase_04 AC 3 ms
5,752 KB
testcase_05 AC 6 ms
5,876 KB
testcase_06 AC 18 ms
5,972 KB
testcase_07 AC 23 ms
6,112 KB
testcase_08 AC 90 ms
8,008 KB
testcase_09 AC 26 ms
6,112 KB
testcase_10 AC 131 ms
8,248 KB
testcase_11 AC 132 ms
8,248 KB
testcase_12 AC 130 ms
8,248 KB
testcase_13 AC 3 ms
5,748 KB
testcase_14 AC 2 ms
5,748 KB
testcase_15 AC 2 ms
5,748 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