# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
745886 |
2023-05-21T09:19:24 Z |
vjudge1 |
Kitchen (BOI19_kitchen) |
C++17 |
|
49 ms |
1036 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
void imp() {
cout << "Impossible";
cout << "\n";
exit(0);
}
int n, m, k;
vector<int> a, b;
int sum_a;
/*int try_4(int idx) {
int pref = 0;
for(int i = 0; i <= idx; i++) {
pref += b[i];
}
if(pref < sum_a) {
return -1;
}
int sum1 = 0;
for(int i = 0; i <= idx; i++) {
sum1 += min(n, b[idx]);
}
if(sum1 < n * k) {
return -1;
}
return pref - sum_a;
}*/
void solve() {
cin >> n >> m >> k;
a.resize(n), b.resize(m);
for(int &x : a) {
cin >> x;
sum_a += x;
}
sort(a.begin(), a.end());
for(int &x : b) {
cin >> x;
}
sort(b.begin(), b.end());
reverse(b.begin(), b.end());
for(int i = 0; i < n; i++) {
if(a[i] < k) {
imp();
}
}
/*int l = -1, r = m;
bool possible = false;
int result = -42;
while(l < r - 1) {
int mid = (l + r) / 2;
int res = try_4(mid);
if(res != -1 && (result == -42 || result > res)) {
result = res;
}
if(res != -1) {
r = mid;
} else {
l = mid;
}
}
if(r == m) {
imp();
}
cout << result << "\n";*/
int maxx = 300 * 300;
vector<int> dp(1 + maxx, 0);
vector<bool> is(1 + maxx, false);
is[0] = true;
for(int i = 1; i <= m; i++) {
int val = b[i - 1];
int other_val = min(b[i - 1], n);
for(int j = maxx; j >= val; j--) {
if(is[j - val]) {
is[j] = true;
dp[j] = max(dp[j], dp[j - val] + other_val);
}
}
}
for(int i = sum_a; i <= maxx; i++) {
if(is[i] && dp[i] >= n * k) {
cout << i - sum_a << "\n";
return;
}
}
imp();
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
3 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
980 KB |
Output is correct |
2 |
Correct |
18 ms |
980 KB |
Output is correct |
3 |
Correct |
34 ms |
980 KB |
Output is correct |
4 |
Correct |
37 ms |
980 KB |
Output is correct |
5 |
Correct |
33 ms |
1036 KB |
Output is correct |
6 |
Correct |
16 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
3 ms |
980 KB |
Output is correct |
3 |
Correct |
3 ms |
980 KB |
Output is correct |
4 |
Correct |
4 ms |
980 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
3 ms |
980 KB |
Output is correct |
13 |
Correct |
2 ms |
980 KB |
Output is correct |
14 |
Correct |
24 ms |
980 KB |
Output is correct |
15 |
Correct |
18 ms |
980 KB |
Output is correct |
16 |
Correct |
34 ms |
980 KB |
Output is correct |
17 |
Correct |
37 ms |
980 KB |
Output is correct |
18 |
Correct |
33 ms |
1036 KB |
Output is correct |
19 |
Correct |
16 ms |
980 KB |
Output is correct |
20 |
Correct |
4 ms |
980 KB |
Output is correct |
21 |
Correct |
3 ms |
980 KB |
Output is correct |
22 |
Correct |
3 ms |
980 KB |
Output is correct |
23 |
Correct |
4 ms |
980 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
21 ms |
980 KB |
Output is correct |
26 |
Correct |
19 ms |
980 KB |
Output is correct |
27 |
Correct |
15 ms |
980 KB |
Output is correct |
28 |
Correct |
39 ms |
980 KB |
Output is correct |
29 |
Correct |
31 ms |
980 KB |
Output is correct |
30 |
Correct |
49 ms |
980 KB |
Output is correct |