結果

問題 No.817 Coin donation
ユーザー akakimidoriakakimidori
提出日時 2019-04-19 21:47:14
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 748 bytes
コンパイル時間 1,104 ms
コンパイル使用メモリ 29,808 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-24 01:22:20
合計ジャッジ時間 2,074 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t i32;
typedef int64_t i64;

#define MIN(a,b) ((a) < (b) ? (a) : (b))

void run (void) {
  i32 n, k;
  scanf ("%" SCNi32 "%" SCNi32, &n, &k);
  i32 *a = (i32 *) calloc (2 * n, sizeof (i32));
  i32 *b = a + n;
  for (i32 i = 0; i < n; ++i) {
    scanf ("%" SCNi32 "%" SCNi32, a + i, b + i);
  }
  i32 l = 0;
  i32 r = 1000000000;
  while (r - l > 1) {
    i32 m = (l + r) / 2;
    i64 cnt = 0;
    for (i32 i = 0; i < n; ++i) {
      if (m < a[i]) continue;
      cnt += MIN(m - a[i] + 1, b[i] - a[i] + 1);
    }
    if (cnt >= k) {
      r = m;
    } else {
      l = m;
    }
  }
  printf ("%" PRIi32 "\n", r);
}

int main (void) {
  run();
  return 0;
}
0