結果

問題 No.817 Coin donation
ユーザー hanbei_dayohanbei_dayo
提出日時 2020-08-21 11:12:31
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 90 ms / 2,000 ms
コード長 1,123 bytes
コンパイル時間 999 ms
コンパイル使用メモリ 104,084 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-04-22 10:35:51
合計ジャッジ時間 2,602 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,812 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 5 ms
6,940 KB
testcase_06 AC 14 ms
6,940 KB
testcase_07 AC 17 ms
6,944 KB
testcase_08 AC 62 ms
6,944 KB
testcase_09 AC 20 ms
6,940 KB
testcase_10 AC 90 ms
6,944 KB
testcase_11 AC 90 ms
6,944 KB
testcase_12 AC 90 ms
6,944 KB
testcase_13 AC 2 ms
6,944 KB
testcase_14 AC 2 ms
6,940 KB
testcase_15 AC 2 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1e8;

vector<int>a,b;
int n;
ll k;

bool check(int x){
    ll num = 0;
    for(int i=0;i<n;i++){
        if(a[i]>x)continue;
        if(a[i]==x){
            num++;
            continue;
        }
        if(b[i]<x){
            num+=b[i]-a[i]+1;
            continue;
        }
        if(a[i]<=x && x<=b[i]){
            num+=x-a[i]+1;
            continue;
        }
    }
    return num>=k;
}

int main() {
    cin>>n>>k;
    a.resize(n),b.resize(n);
    int ng = -1,ok = 0;
    for(int i=0;i<n;i++){
        cin>>a[i]>>b[i];
        ok = max(ok,b[i]);
    }
    while(ok-ng>1){
        int mid = (ok+ng)/2;
        if(check(mid))ok = mid;
        else ng = mid;
    }
    cout<<ok<<endl;
}
0