結果

問題 No.817 Coin donation
ユーザー ama_nukoama_nuko
提出日時 2019-04-20 00:15:33
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,619 bytes
コンパイル時間 937 ms
コンパイル使用メモリ 98,288 KB
実行使用メモリ 4,772 KB
最終ジャッジ日時 2023-10-24 16:44:45
合計ジャッジ時間 1,752 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 3 ms
4,348 KB
testcase_06 AC 6 ms
4,348 KB
testcase_07 AC 7 ms
4,348 KB
testcase_08 AC 21 ms
4,348 KB
testcase_09 AC 7 ms
4,348 KB
testcase_10 AC 30 ms
4,772 KB
testcase_11 AC 29 ms
4,772 KB
testcase_12 AC 30 ms
4,772 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 <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];

    int lo = 1;
    int hi = 1e9;
    while(hi - lo > 1){
        int mid = (lo + hi) / 2;

        int sum = 0;
        int eq = 0;
        rep(i, n){
            if(mid < a[i]){
                continue;
            }
            sum += min(mid, b[i]) - a[i] + 1;
            if(a[i] <= mid && mid <= b[i]){
                eq++;
            }
        }
        if(sum - eq + 1 <= k){
            lo = mid;
        }else{
            hi = mid;
        }
    }
    cout << lo << endl;

    return 0;
}
0