結果

問題 No.817 Coin donation
ユーザー ats5515ats5515
提出日時 2019-04-20 17:44:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-09 19:15:33
合計ジャッジ時間 2,900 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,812 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 7 ms
6,940 KB
testcase_07 AC 8 ms
6,940 KB
testcase_08 AC 29 ms
6,940 KB
testcase_09 AC 9 ms
6,940 KB
testcase_10 AC 42 ms
6,944 KB
testcase_11 AC 41 ms
6,940 KB
testcase_12 AC 42 ms
6,940 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 1 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <stdio.h>
using namespace std;
#define int long long
int MOD = 1000000007;
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	vector<int> B(N);
	int res = 0;
	for (int i = 0; i < N; i++) {
		cin >> A[i] >> B[i];
	}

	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	vector<int> sumA(N + 1, 0);
	vector<int> sumB(N + 1, 0);
	for (int i = 0; i < N; i++) {
		sumA[i + 1] = sumA[i] + A[i];
		sumB[i + 1] = sumB[i] + B[i];
	}

	int ok = 1e9;
	int ng = 0;

	while (ok - ng > 1) {
		int m = (ok + ng) / 2;
		int ans = 0;

		int k = upper_bound(A.begin(), A.end(), m) - A.begin();
		ans += k * m;
		ans -= sumA[k] - k;

		k = upper_bound(B.begin(), B.end(), m) - B.begin();
		ans -= k * m;
		ans += sumB[k];
		//cerr << m << " " << ans << endl;

		if (ans >= K) {
			ok = m;
		}
		else {
			ng = m;
		}
	}


	cout << ok << endl;
}
0