結果
| 問題 | No.1715 Dinner 2 |
| コンテスト | |
| ユーザー |
siman
|
| 提出日時 | 2021-10-25 04:21:49 |
| 言語 | C++17(clang) (clang++ 22.1.2 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,152 bytes |
| 記録 | |
| コンパイル時間 | 5,609 ms |
| コンパイル使用メモリ | 151,424 KB |
| 実行使用メモリ | 6,400 KB |
| 最終ジャッジ日時 | 2026-04-18 22:37:12 |
| 合計ジャッジ時間 | 6,504 ms |
|
ジャッジサーバーID (参考情報) |
judge3_1 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 6 WA * 32 |
コンパイルメッセージ
main.cpp:31:16: warning: variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension]
31 | bool checked[N];
| ^
main.cpp:31:16: note: read of non-const variable 'N' is not allowed in a constant expression
main.cpp:26:5: note: declared here
26 | int N, D;
| ^
1 warning generated.
ソースコード
#include <cassert>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <limits.h>
#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;
bool checked[N];
memset(checked, false, sizeof(checked));
for (int d = 0; d < D; ++d) {
bool ok = false;
for (int i = 0; i < N; ++i) {
if (checked[i]) continue;
Food &food = foods[i];
if (val - food.p < x) continue;
val -= food.p;
val += food.q;
checked[i] = true;
ok = true;
break;
}
if (not ok) return false;
}
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;
}
siman