結果

問題 No.817 Coin donation
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-04-21 18:29:49
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,305 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 75,044 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-16 06:30:37
合計ジャッジ時間 1,851 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 1 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0