結果

問題 No.817 Coin donation
ユーザー totori_nyaatotori_nyaa
提出日時 2019-04-19 22:49:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,136 bytes
コンパイル時間 2,056 ms
コンパイル使用メモリ 175,952 KB
実行使用メモリ 8,152 KB
最終ジャッジ日時 2023-10-24 06:25:03
合計ジャッジ時間 3,532 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 4 ms
4,348 KB
testcase_03 AC 6 ms
4,348 KB
testcase_04 AC 3 ms
4,348 KB
testcase_05 AC 6 ms
4,348 KB
testcase_06 AC 18 ms
4,348 KB
testcase_07 AC 21 ms
4,348 KB
testcase_08 AC 78 ms
8,152 KB
testcase_09 AC 24 ms
4,348 KB
testcase_10 AC 114 ms
8,152 KB
testcase_11 AC 113 ms
8,152 KB
testcase_12 AC 112 ms
8,152 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>
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