結果

問題 No.817 Coin donation
ユーザー puni_kyopropuni_kyopro
提出日時 2019-08-16 21:06:36
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 2,258 bytes
コンパイル時間 1,018 ms
コンパイル使用メモリ 99,664 KB
実行使用メモリ 20,488 KB
最終ジャッジ日時 2023-10-23 21:07:26
合計ジャッジ時間 2,863 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 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 6 ms
4,348 KB
testcase_06 AC 27 ms
5,564 KB
testcase_07 AC 35 ms
6,272 KB
testcase_08 AC 172 ms
15,248 KB
testcase_09 AC 42 ms
6,848 KB
testcase_10 AC 260 ms
20,488 KB
testcase_11 AC 262 ms
20,488 KB
testcase_12 AC 263 ms
20,488 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 1 ms
4,348 KB
testcase_15 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include<cstring>
#include<queue>
#include<map>
#include<set>
#include<climits>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
	return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
	for (auto& e : t) fill_v(e, v);
}


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

int dx[4] = { 1,0,0,-1 };
int dy[4] = { 0,1,-1,0 };


/******************************************************************************************/

int main() {

	ll n, k;
	cin >> n >> k;
	vector<ll> a(n), b(n);

	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
	}

	vector<ll> v;
	map<ll, ll> mp;

	for (int i = 0; i < n; i++)
	{
		v.push_back(a[i]);
		v.push_back(b[i] + 1);//いもすするために+1
	}


	//座標圧縮
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());

	for (int i = 0; i < v.size(); i++)
	{
		mp[v[i]] = i;
	}


	vector<ll> imos(v.size() + 10, 0);

	for (int i = 0; i < n; i++)
	{
		imos[mp[a[i]]]++;
		imos[mp[b[i]+1]]--;
	}

	for (int i = 0; i < imos.size() - 1; i++)
	{
		imos[i + 1] += imos[i];
	}
	

	ll cnt = 0;

	for (int i = 0; i < imos.size() - 1; i++)
	{
		ll left = v[i];
		ll right = v[i + 1] - 1;
		ll sum = imos[i] * (right - left + 1);
		if (cnt + sum >= k) {
			ll posi = left + (k - cnt) / imos[i] + min((k - cnt) % imos[i], 1LL) - 1;
			cout << posi << endl;
			return 0;
		}
		cnt += sum;
	}


	return 0;
}
0