結果
| 問題 |
No.817 Coin donation
|
| コンテスト | |
| ユーザー |
Im_Gimlet
|
| 提出日時 | 2020-09-02 14:56:24 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 84 ms / 2,000 ms |
| コード長 | 1,262 bytes |
| コンパイル時間 | 1,950 ms |
| コンパイル使用メモリ | 167,824 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-11-21 14:10:08 |
| 合計ジャッジ時間 | 3,345 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 14 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;
using P = pair<ll, ll>;
const long double PI = acos(-1.0L);
ll GCD(ll a, ll b) { return b?GCD(b, a%b):a; }
ll LCM(ll a, ll b) { return a/GCD(a, b)*b; }
int main() {
ll n, k; cin >> n >> k;
vector<ll> avec(n, 0);
vector<ll> bvec(n, 0);
for(int i = 0; i < n; ++i) {
cin >> avec[i] >> bvec[i];
}
ll ok = 1e9; ll ng = 0;
while(abs(ok-ng) > 1) {
ll mid = (ok+ng)/2;
auto isOK = [&](ll key) {
// n個の幅についてチェックしていく
ll cnt = 0;
for(int i = 0; i < n; ++i) {
if(avec[i] <= key) {
if(bvec[i] <= key) {
cnt += (bvec[i]-avec[i]+1);
}else {
cnt += (key-avec[i]+1);
}
}
}
if(cnt >= k) return true;
else return false;
};
if(isOK(mid)) ok = mid;
else ng = mid;
}
cout << ok << endl;
}
Im_Gimlet