結果

問題 No.817 Coin donation
ユーザー sykwersykwer
提出日時 2019-04-19 21:43:38
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 890 ms
使用メモリ 5,052 KB
最終ジャッジ日時 2022-11-22 08:06:48
合計ジャッジ時間 2,449 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,384 KB
testcase_01 AC 1 ms
3,432 KB
testcase_02 AC 1 ms
3,392 KB
testcase_03 AC 2 ms
3,484 KB
testcase_04 AC 2 ms
3,448 KB
testcase_05 AC 4 ms
3,456 KB
testcase_06 AC 12 ms
3,668 KB
testcase_07 AC 15 ms
3,768 KB
testcase_08 AC 55 ms
4,420 KB
testcase_09 AC 18 ms
3,656 KB
testcase_10 AC 79 ms
5,052 KB
testcase_11 AC 80 ms
4,972 KB
testcase_12 AC 81 ms
4,936 KB
testcase_13 AC 1 ms
3,340 KB
testcase_14 AC 2 ms
3,432 KB
testcase_15 AC 1 ms
3,424 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>
#include <cstring>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

const int MAX_N = 100000;
int N, K;
int A[MAX_N];
int B[MAX_N];

bool f(int x) {
    int num = 0;
    for (int i = 0; i < N; i++) {
        num += max(0LL, min(x, B[i]) - A[i] + 1);
    }
    return num >= K;
}

signed main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> A[i] >> B[i];
    int lb = 0;
    int ub = INF;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (f(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }
    cout << ub << endl;
    return 0;
}
0