結果
| 問題 |
No.817 Coin donation
|
| コンテスト | |
| ユーザー |
@abcde
|
| 提出日時 | 2019-05-19 22:36:51 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 86 ms / 2,000 ms |
| コード長 | 1,485 bytes |
| コンパイル時間 | 1,493 ms |
| コンパイル使用メモリ | 175,548 KB |
| 実行使用メモリ | 5,584 KB |
| 最終ジャッジ日時 | 2024-09-17 06:33:49 |
| 合計ジャッジ時間 | 2,570 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
// TODO: 高速化.
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
// 1. 入力情報取得.
LL N, K;
cin >> N >> K;
// 2. 硬貨準備.
vector<pair<LL, LL>> v;
LL upper = 0;
for(int i = 0; i < N; i++){
LL a, b;
cin >> a >> b;
upper = max(upper, b);
v.push_back(make_pair(a, b));
}
// 3. 昇順sort.
sort(v.begin(), v.end());
// 4. K番目を探索.
LL ans = 0;
// int counter = 0;
LL l = -1, r = upper;
while(1){
// 4-1. 探索.
// 今回調査する硬貨の金額.
LL cur = (l + r) / 2;
LL sIndex = 0, eIndex = 0;
for(auto &p : v){
if(p.first > cur) break;
LL cur1 = min(cur - 1, p.second);
LL cur2 = min(cur, p.second);
sIndex += cur1 - p.first + 1;
eIndex += cur2 - p.first + 1;
}
// 4-2. 終了条件チェック.
// 4-2-1. K番目に安い硬貨が, 見つかった場合.
if(sIndex + 1 <= K && K <= eIndex){
ans = cur;
break;
}
// 4-2-2. K番目に安い硬貨が, 見つからなかった場合.
if(K < sIndex + 1) r = cur;
if(K > eIndex) l = cur;
// debug.
// if(counter > 500) break;
// counter++;
}
// 5. 後処理.
cout << ans << endl;
return 0;
}
@abcde