結果

問題 No.1715 Dinner 2
ユーザー siman
提出日時 2021-10-25 04:33:02
言語 C++17(clang)
(17.0.6 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,238 bytes
コンパイル時間 3,122 ms
コンパイル使用メモリ 143,220 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-10-02 13:39:25
合計ジャッジ時間 2,423 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35 WA * 3
権限があれば一括ダウンロードができます

ソースコード

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