結果
| 問題 |
No.817 Coin donation
|
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2019-04-21 18:29:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,305 bytes |
| コンパイル時間 | 596 ms |
| コンパイル使用メモリ | 75,012 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-06 19:56:26 |
| 合計ジャッジ時間 | 1,752 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 6 WA * 8 |
ソースコード
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <stack>
#include <math.h>
#include <set>
#define ALL(obj) (obj).begin(),(obj).end()
#define RALL(obj) (obj).rbegin(),(obj).rend()
#define P pair<int, int>
#define MOD 1000000007
#define INF 2147483647
#define NINF (-2147483647-1)
#define LLINF 9223372036854775807
using ll = long long;
using namespace std;
int K, N;
// a円以上の硬貨がK枚以上あるか
bool fun(int a, const vector<P> A) {
int cnt = 0;
for (int i = 0; i < N; i++)
{
if (A[i].first <= a && A[i].second > a) {
cnt += a - A[i].first + 1;
}
else if (A[i].second <= a) {
cnt += A[i].second - A[i].first + 1;
}
}
if (cnt >= K) return true;
return false;
}
int main() {
cin >> N >> K;
vector<P> A(N);
int m = -1;
for (int i = 0; i < N; i++)
{
cin >> A[i].first >> A[i].second;
m = max(m, A[i].second);
}
int left = 0, right = m;
while (left < right - 1) {
if (fun((left + right) / 2, A)) {
right = (left + right) / 2;
}
else {
left = (left + right) / 2;
}
}
cout << right << endl;
getchar(); getchar();
return 0;
}
🍮かんプリン