結果

問題 No.817 Coin donation
ユーザー もりをもりを
提出日時 2019-04-20 01:06:09
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 620 bytes
コンパイル時間 1,831 ms
コンパイル使用メモリ 171,804 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 22:51:33
合計ジャッジ時間 4,210 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 60 ms
4,348 KB
testcase_09 AC 19 ms
4,348 KB
testcase_10 AC 87 ms
4,348 KB
testcase_11 AC 87 ms
4,348 KB
testcase_12 AC 87 ms
4,348 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;
typedef long long ll;

int N, K;
vector<pair<int,int>> query;

signed main() {

  cin >> N >> K;

  query.resize(N);
  for (int i = 0; i < N; ++i) {
    cin >> query[i].first >> query[i].second;
  }

  int ok = (int)1e9, ng = 0;
  while (abs(ok - ng) > 1) {
    int mid = (ok + ng) / 2;
    ll cnt = 0;
    for (auto& q : query) {
      int a, b;
      tie(a, b) = q;
      if (b <= mid) cnt += b - a + 1;
      else if (a <= mid) cnt += mid - a + 1;
    }
    if (cnt >= K) ok = mid;
    else ng = mid;
    // cerr << ok << ' ' << ng << endl;
  }

  cout << ok << endl;

}
0