結果
| 問題 |
No.817 Coin donation
|
| コンテスト | |
| ユーザー |
merom686
|
| 提出日時 | 2019-04-19 21:51:12 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 993 bytes |
| コンパイル時間 | 779 ms |
| コンパイル使用メモリ | 76,624 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 18:30:37 |
| 合計ジャッジ時間 | 1,557 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;
template <class F>
int lower_bound(int i0, int i1, F f) {
while (i0 < i1) {
int i = (i0 + i1) / 2;
if (f(i)) i1 = i; else i0 = i + 1;
}
return i0;
}
struct P {
int a, b;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, k;
cin >> n >> k;
vector<P> p(n);
for (int i = 0; i < n; i++) {
int a, b;
cin >> a >> b;
p[i] = { a, b + 1 };
}
//c円以下のものがk枚あるか 満たす中で最も小さいもの
int c = lower_bound(1, 1 << 30, [&](int c) {
ll s = 0;
for (int i = 0; i < n; i++) {
if (c < p[i].a) continue;
if (c < p[i].b) s += c + 1 - p[i].a; else s += p[i].b - p[i].a;
}
return s >= (ll)k;
});
cout << c << endl;
return 0;
}
merom686