結果

問題 No.817 Coin donation
ユーザー pekempeypekempey
提出日時 2019-04-19 21:42:23
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 86 ms / 2,000 ms
コード長 587 bytes
コンパイル時間 609 ms
コンパイル使用メモリ 71,576 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 00:52:24
合計ジャッジ時間 1,838 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 85 ms
4,348 KB
testcase_11 AC 86 ms
4,348 KB
testcase_12 AC 86 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 <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