結果

問題 No.817 Coin donation
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2019-04-22 10:34:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 79 ms / 2,000 ms
コード長 1,163 bytes
コンパイル時間 614 ms
コンパイル使用メモリ 74,328 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-18 02:19:04
合計ジャッジ時間 1,770 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 1 ms
5,376 KB
testcase_05 AC 4 ms
5,376 KB
testcase_06 AC 10 ms
5,376 KB
testcase_07 AC 14 ms
5,376 KB
testcase_08 AC 53 ms
5,376 KB
testcase_09 AC 16 ms
5,376 KB
testcase_10 AC 79 ms
5,376 KB
testcase_11 AC 76 ms
5,376 KB
testcase_12 AC 75 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 1 ms
5,376 KB
testcase_15 AC 2 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 main() {
    int K, N;
    cin >> N >> K;
    vector<P> A(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i].first >> A[i].second;
    }
    int left = 0, right = INF;
    while (left < right - 1) {
        int mid = (left + right) / 2;
        ll cnt = 0;
        for (int i = 0; i < N; i++)
        {
            if (A[i].first > mid) continue;
            if (A[i].second > mid) {
                cnt += mid - A[i].first + 1;
            }
            else {
                cnt += A[i].second - A[i].first + 1;
            }
        }
        if (cnt >= K) {
            right = mid;
        }
        else {
            left = mid;
        }
    }
    cout << right << endl;
    getchar(); getchar();
    return 0;
}
0