結果

問題 No.817 Coin donation
ユーザー pekempeypekempey
提出日時 2019-04-19 21:42:23
言語 C++14
(gcc 11.2.0 + boost 1.78.0)
結果
AC  
実行時間 68 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 541 ms
使用メモリ 3,968 KB
最終ジャッジ日時 2022-11-22 07:53:34
合計ジャッジ時間 1,918 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 2 ms
3,420 KB
testcase_01 AC 1 ms
3,496 KB
testcase_02 AC 2 ms
3,508 KB
testcase_03 AC 2 ms
3,376 KB
testcase_04 AC 1 ms
3,532 KB
testcase_05 AC 4 ms
3,508 KB
testcase_06 AC 11 ms
3,664 KB
testcase_07 AC 14 ms
3,552 KB
testcase_08 AC 52 ms
3,576 KB
testcase_09 AC 16 ms
3,680 KB
testcase_10 AC 68 ms
3,884 KB
testcase_11 AC 68 ms
3,968 KB
testcase_12 AC 65 ms
3,840 KB
testcase_13 AC 2 ms
3,380 KB
testcase_14 AC 2 ms
3,480 KB
testcase_15 AC 1 ms
3,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N), B(N);
  long long s = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i] >> B[i];
    B[i]++;
    s += B[i] - A[i];
  }
  int l = 0;
  int r = (int)1e9 + 1;
  while (r - l > 1) {
    int m = (l + r) / 2;
    long long c = 0;
    for (int i = 0; i < N; i++) {
      c += max(0, m - A[i]);
      c -= max(0, m - B[i]);
    }
    if (c >= K) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << l << endl;
}
0