結果

問題 No.817 Coin donation
ユーザー hiro71687khiro71687k
提出日時 2023-03-24 03:29:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 847 bytes
コンパイル時間 4,114 ms
コンパイル使用メモリ 262,564 KB
実行使用メモリ 4,888 KB
最終ジャッジ日時 2023-10-18 19:52:02
合計ジャッジ時間 6,263 ms
ジャッジサーバーID
(参考情報)
judge14 / 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 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,360 KB
testcase_09 AC 18 ms
4,348 KB
testcase_10 AC 85 ms
4,888 KB
testcase_11 AC 85 ms
4,888 KB
testcase_12 AC 86 ms
4,888 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>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll=long long;
using ld=long double;
ld pie=3.141592653589793;
ll inf=144499999994;
ll mod=1000000007;
int main(){
    ll n,k;
    cin >> n >> k;
    vector<ll>a(n),b(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> a[i] >> b[i];
    }
    ll left=0,right=inf;
    while (right-left>1)
    {
        ll mid=(right+left)/2;
        ll x=0;
        for (ll i = 0; i < n; i++)
        {
            if (mid>=a[i])
            {
                if (mid>=b[i])
                {
                    x+=b[i]-a[i]+1;
                }else{
                    x+=mid-a[i]+1;
                }
            }
        }
        if (x<k)
        {
            left=mid;
        }else{
            right=mid;
        }
    }
    cout << right << endl;
}
0