結果

問題 No.817 Coin donation
ユーザー sykwersykwer
提出日時 2019-04-19 21:43:38
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 88 ms / 2,000 ms
コード長 1,297 bytes
コンパイル時間 2,304 ms
コンパイル使用メモリ 109,336 KB
実行使用メモリ 5,208 KB
最終ジャッジ日時 2023-10-24 01:07:26
合計ジャッジ時間 2,194 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 60 ms
4,728 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 88 ms
5,208 KB
testcase_11 AC 88 ms
5,208 KB
testcase_12 AC 87 ms
5,208 KB
testcase_13 AC 2 ms
4,348 KB
testcase_14 AC 2 ms
4,348 KB
testcase_15 AC 2 ms
4,348 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