結果

問題 No.817 Coin donation
ユーザー yuliicppyyuliicppy
提出日時 2019-04-24 17:22:40
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 2,442 bytes
コンパイル時間 731 ms
コンパイル使用メモリ 83,940 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-25 16:59:02
合計ジャッジ時間 2,086 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>
#include <set>

using namespace std;

//#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;
int N,K;
vector<PII> E;

bool isOK(int mid, int key)
{
    int cnt = 0;
    dump(mid)
    REP(i,N)
    {
        int A = E[i].first;
        int B = E[i].second;
        if(A <= mid && mid <= B)
        {
            cnt += mid - A + 1;
        }
        else if(B < mid)
        {
            cnt += B - A + 1;
        }
    }
    dump(cnt)

    if(cnt >= key) return true;
    else return false;
}

int binary_search(int key) {
    int ng = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int ok = 1e9; // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
    /* どんな二分探索でもここの書き方を変えずにできる! */
    while (abs(ng - ok) > 1) {
        int mid = (ok + ng) / 2;
        if (isOK(mid, key)) ok = mid;
        else ng = mid;
    }
    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return ok;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N>>K;
    REP(i,N)
    {
        int ta,tb; cin >> ta >> tb;
        E.pb(make_pair(ta,tb));
    }
    dump("check")
    int ans = binary_search(K);
    cout << ans << endl;



}
0