結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
権限があれば一括ダウンロードができます

ソースコード

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++)
	{
		cout << i << endl;
		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