結果

問題 No.1715 Dinner 2
ユーザー simansiman
提出日時 2021-10-25 04:33:02
言語 C++17(clang)
(14.0.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 1,919 ms
コンパイル使用メモリ 104,748 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-25 20:00:49
合計ジャッジ時間 3,742 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,376 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,384 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,376 KB
testcase_11 AC 21 ms
4,380 KB
testcase_12 AC 15 ms
4,380 KB
testcase_13 AC 13 ms
4,376 KB
testcase_14 AC 20 ms
4,376 KB
testcase_15 AC 18 ms
4,376 KB
testcase_16 AC 16 ms
4,376 KB
testcase_17 AC 10 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 4 ms
4,380 KB
testcase_26 AC 3 ms
4,376 KB
testcase_27 AC 3 ms
4,376 KB
testcase_28 AC 3 ms
4,376 KB
testcase_29 AC 3 ms
4,376 KB
testcase_30 AC 3 ms
4,376 KB
testcase_31 AC 4 ms
4,376 KB
testcase_32 AC 25 ms
4,376 KB
testcase_33 AC 28 ms
4,380 KB
testcase_34 AC 28 ms
4,376 KB
testcase_35 AC 29 ms
4,380 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <climits>
#include <map>
#include <queue>
#include <set>
#include <string.h>
#include <vector>

using namespace std;
typedef long long ll;

struct Food {
  int p;
  int q;

  Food(int p, int q) {
    this->p = p;
    this->q = q;
  }
};

int N, D;
vector<Food> foods;

bool f(int x) {
  int val = 0;
  int checked[N];
  memset(checked, -1, sizeof(checked));

  for (int d = 1; d <= D; ++d) {
    int best_i = -1;
    int max_v = INT_MIN;

    for (int i = 0; i < N; ++i) {
      if (checked[i] == d - 1) continue;
      Food &food = foods[i];
      if (val - food.p < x) continue;
      int v = food.q - food.p;

      if (max_v < v) {
        max_v = v;
        best_i = i;
      }
    }

    if (best_i == -1) return false;
    checked[best_i] = d;
    val += max_v;
  }

  return true;
}

int main() {
  cin >> N >> D;

  for (int i = 0; i < N; ++i) {
    int p, q;
    cin >> p >> q;
    foods.push_back(Food(p, q));
  }

  int ok = -100000000;
  int ng = 1000000;

  while (abs(ok - ng) >= 2) {
    int x = (ok + ng) / 2;

    if (f(x)) {
      ok = x;
    } else {
      ng = x;
    }
  }

  cout << ok << endl;

  return 0;
}
0