結果

問題 No.817 Coin donation
ユーザー totori_nyaatotori_nyaa
提出日時 2019-04-19 22:49:04
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 93 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 1,339 ms
使用メモリ 7,360 KB
最終ジャッジ日時 2022-11-22 14:48:52
合計ジャッジ時間 3,042 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 1 ms
3,488 KB
testcase_01 AC 1 ms
3,404 KB
testcase_02 AC 2 ms
3,412 KB
testcase_03 AC 4 ms
3,488 KB
testcase_04 AC 1 ms
3,360 KB
testcase_05 AC 4 ms
3,596 KB
testcase_06 AC 14 ms
3,720 KB
testcase_07 AC 17 ms
4,100 KB
testcase_08 AC 63 ms
7,268 KB
testcase_09 AC 21 ms
4,180 KB
testcase_10 AC 90 ms
7,360 KB
testcase_11 AC 92 ms
7,268 KB
testcase_12 AC 93 ms
7,200 KB
testcase_13 AC 1 ms
3,440 KB
testcase_14 AC 1 ms
3,408 KB
testcase_15 AC 1 ms
3,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;

int main(){
    long long n,k;
    cin>>n>>k;
    long long a,b;
    vector<pair<long long,long long>> v;
    for(long long i=0;i<n;i++){
        cin>>a>>b;
        v.push_back(make_pair(a,0));
        v.push_back(make_pair(b,1));
    }
    sort(v.begin(),v.end());

    long long c=0;
    long long t=1;
    long long p=0;
    p=v[0].first;
    for(long long i=1;i<v.size();i++){
        if(v[i].second==0){
            c+=(v[i].first-p)*t;
            p=v[i].first-1;
            if(c>=k){
                cerr<<i<<" "<<c<<" "<<t<<" "<<p<<endl;
                long long ans=p-(c-k)/t;
                cout<<ans<<endl;
                return 0;
            }
            t++;
            p=v[i].first;
        }
        else {
            c+=(v[i].first-p+1)*t;
            p=v[i].first;
            if(c>=k){
                cerr<<i<<" "<<c<<" "<<t<<" "<<p<<endl;
                long long ans=p-(c-k)/t;
                cout<<ans<<endl;
                return 0;
            }
            t--;
            p=v[i].first+1;
        }
        cerr<<i<<" "<<c<<" "<<t<<" "<<p<<endl;
    }
}
0