結果

問題 No.817 Coin donation
ユーザー tactac
提出日時 2019-04-20 11:47:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 115 ms / 2,000 ms
コード長 1,259 bytes
コンパイル時間 1,068 ms
コンパイル使用メモリ 113,604 KB
実行使用メモリ 4,396 KB
最終ジャッジ日時 2023-10-26 01:43:10
合計ジャッジ時間 2,406 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
4,348 KB
testcase_05 AC 5 ms
4,348 KB
testcase_06 AC 17 ms
4,348 KB
testcase_07 AC 21 ms
4,348 KB
testcase_08 AC 80 ms
4,348 KB
testcase_09 AC 25 ms
4,348 KB
testcase_10 AC 115 ms
4,396 KB
testcase_11 AC 115 ms
4,396 KB
testcase_12 AC 115 ms
4,396 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 #

#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<stack>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<sstream>
#include<random>
#include<cassert>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
const int inf = 1e9 + 7;
int dy[] = {0, 0, -1, 1, -1, 1, -1, 1};
int dx[] = {1, -1, 0, 0, -1, 1, 1, -1};
#define ceil(a, b) a / b + !!(a % b)

int main() {
    int n, k;
    cin >> n >> k;
    int a[n], b[n];
    rep(i, n) cin >> a[i] >> b[i];
    int l = 1, r = 1e9 + 1;
    int cou = 0;
    while (l + 1 < r) { //break when l + 1 = r
        cou++;
        if (cou > 300) break;
        int mid = (l + r) / 2;
        //cout << l << " " << mid << " " << r << endl;
        ll c = 0;
        rep(i, n) { //何枚がmid円以下か
            c += (ll)max(0, min(mid, b[i]) - a[i] + 1);
        }
        //cout << c << endl;
        if (c >= k) { //足りてるから数字大きくする
            r = mid + 1;
        } else { //足りない
            l = mid;
        }
        //cout << l << " " << mid << " " << r << endl;
    }
    cout << l + 1 << endl;
}
0