結果

問題 No.817 Coin donation
ユーザー tekihei2317tekihei2317
提出日時 2019-04-19 21:44:24
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 708 bytes
コンパイル時間 1,532 ms
コンパイル使用メモリ 169,792 KB
実行使用メモリ 4,960 KB
最終ジャッジ日時 2023-10-24 01:08:11
合計ジャッジ時間 2,725 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 4 ms
4,348 KB
testcase_06 AC 13 ms
4,348 KB
testcase_07 AC 16 ms
4,348 KB
testcase_08 AC 59 ms
4,432 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 85 ms
4,960 KB
testcase_11 AC 85 ms
4,960 KB
testcase_12 AC 85 ms
4,960 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<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) ((int)(x).size())
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

int N,K;
vint a,b;

bool check(int x)
{// x以下の数がK個数以上あるか
    int cnt=0;
    REP(i,N){
        if(a[i]<=x and x<=b[i]) cnt+=x-a[i]+1;
        else if(b[i]<x) cnt+=b[i]-a[i]+1;
    }
    return cnt>=K;
}

signed main()
{
    cin>>N>>K;
    a.resize(N);
    b.resize(N);
    REP(i,N) cin>>a[i]>>b[i];
    
    int ng=0,ok=1e9;
    while(ok-ng>1){
        int mid=(ok+ng)/2;
        if(check(mid)) ok=mid;
        else ng=mid;
    }
    cout<<ok<<endl;
}
0