#include <iostream>
#include <vector>
#include <queue>
using namespace std;
struct meal {
int t, k;
bool operator<(const meal& m)const {
return k < m.k;
}
};
int check(int mask, vector<int>& ch, vector<meal>& m) {
priority_queue<meal> q;
int sum = 0;
for (meal i : m) {
q.push(i);
sum += i.t;
}
for (int i = 0; i < ch.size(); i++) {
if (((1 << i)&mask) == 0)continue;
sum -= ch[i];
vector<meal> out;
for (int j = 0; j < ch[i]; j++) {
if (q.empty())break;
meal x = q.top();
q.pop();
x.k--;
out.push_back(x);
}
for (meal j : out)q.push(j);
}
if (q.top().k > 0 || sum > 0)return INT32_MAX;
return -sum;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m, k;
cin >> n >> m >> k;
vector<meal> meals(n);
bool b = 1;
int sum = 0;
for (int i = 0; i < n; i++) {
cin >> meals[i].t;
meals[i].k = k;
if (meals[i].t < k)b = 0;
sum += meals[i].t;
}
vector<int> ch(m);
for (int& i : ch)cin >> i;
/* for (int i = 0; i < (1 << m); i++) {
ans = min(ans, check(i, ch, meals));
}*/
vector<vector<vector<bool>>> dp(m + 1, vector<vector<bool>>(1601, vector<bool>(1601,0)));
dp[0][0][0] = 1;
for (int i = 0; i < m; i++) {
for (int j = 0; j <= 1600; j++) {
for (int k = 0; k <= 1600; k++) {
if (dp[i][j][k]) {
dp[i + 1][j][k] = 1;
dp[i + 1][j + ch[i]][k + min(ch[i], n)] = 1;
}
}
}
}
if (b) {
for (int i = sum; i <= 1600; i++) {
for (int j = n * k; j <= 1600; j++) {
if (dp[m][i][j]) {
cout << i - sum << '\n';
return 0;
}
}
}
}
cout << "Impossible\n";
}
Compilation message
kitchen.cpp: In function 'int check(int, std::vector<int>&, std::vector<meal>&)':
kitchen.cpp:20:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for (int i = 0; i < ch.size(); i++) {
| ~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
7 ms |
1876 KB |
Output is correct |
3 |
Correct |
7 ms |
1968 KB |
Output is correct |
4 |
Correct |
7 ms |
1876 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
7 ms |
1972 KB |
Output is correct |
7 |
Correct |
7 ms |
1876 KB |
Output is correct |
8 |
Correct |
10 ms |
1876 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
7 ms |
1876 KB |
Output is correct |
3 |
Correct |
7 ms |
1968 KB |
Output is correct |
4 |
Correct |
7 ms |
1876 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
7 ms |
1972 KB |
Output is correct |
7 |
Correct |
7 ms |
1876 KB |
Output is correct |
8 |
Correct |
10 ms |
1876 KB |
Output is correct |
9 |
Runtime error |
31 ms |
14668 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
164 ms |
220904 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
114 ms |
17572 KB |
Output is correct |
2 |
Correct |
124 ms |
17672 KB |
Output is correct |
3 |
Correct |
117 ms |
17676 KB |
Output is correct |
4 |
Correct |
112 ms |
17620 KB |
Output is correct |
5 |
Correct |
118 ms |
17668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
1876 KB |
Output is correct |
2 |
Correct |
7 ms |
1876 KB |
Output is correct |
3 |
Correct |
7 ms |
1968 KB |
Output is correct |
4 |
Correct |
7 ms |
1876 KB |
Output is correct |
5 |
Correct |
6 ms |
1876 KB |
Output is correct |
6 |
Correct |
7 ms |
1972 KB |
Output is correct |
7 |
Correct |
7 ms |
1876 KB |
Output is correct |
8 |
Correct |
10 ms |
1876 KB |
Output is correct |
9 |
Runtime error |
31 ms |
14668 KB |
Execution killed with signal 11 |
10 |
Halted |
0 ms |
0 KB |
- |