#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
/*
int memo[305][305][605], A[305], B[305], dp2[305][305], n, m, k, mx, mn = 1e9, ans = 2e9, sm;
int dp(int x, int y, int cur){
if(x == m + 1){
if(cur < mx || y < k)return 2e9;
return (cur >= mx ? cur - sm : 2e9);
}
if(memo[x][y][cur] != -1)return memo[x][y][cur];
if(cur >= mx){
return memo[x][y][cur] = (dp2[x][max(0, k - y)] + cur) - sm;
}
return memo[x][y][cur] = min(dp(x + 1, y, cur), dp(x + 1, y + 1, cur + B[x]));
}
*/
int n, m, k, A[305], B[305], mx, mn = 1e9, sm, dp[305][305*305 + 300];
void solve(){
cin >> n >> m >> k;
for(int i = 1; i <= n; i++)cin >> A[i], mx = max(mx, A[i]), sm += A[i], mn = min(mn, A[i]);
if(mn < k){
cout << "Impossible\n";
return;
}
for(int i = 1; i <= m; i++)cin >> B[i];
/*
dp2[m+1][0] = 0;
for(int i = 1; i <= m; i++)dp2[m+1][i] = 2e9;
for(int i = m; i >= 1; i--){
for(int j = 0; j <= m; j++){
dp2[i][j] = min(dp2[i+1][j], (j ? dp2[i+1][j-1] + B[i] : (int)1e18));
}
}
memset(memo, -1, sizeof(memo));
int res = dp(1, 0, 0);
if(res > 1e9)cout << "Impossible\n";
else cout << res << '\n';
*/
dp[0][0] = sm;
for(int i = 1; i <= 300 * 300; i++)dp[0][i] = -2e9;
for(int i = 1; i <= m; i++){
for(int j = 0; j <= 300 * 300; j++){
dp[i][j] = max(dp[i-1][j], (j >= B[i] ? dp[i - 1][j - B[i]] - max(0, B[i] - n) : (int)-1e18));
}
}
for(int i = sm; i <= 300 * 300; i++){
if(dp[m][i] >= k * n - (i - sm)){
cout << i - sm << '\n';
return;
}
}
cout << "Impossible";
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int tc = 1;
//cin >> tc;
for(int tc1=1;tc1<=tc;tc1++){
// cout << "Case #" << tc1 << ": ";
solve();
}
}
Compilation message
kitchen.cpp:67:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
67 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
6748 KB |
Output is correct |
10 |
Correct |
3 ms |
6792 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
3 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
96848 KB |
Output is correct |
2 |
Correct |
31 ms |
84564 KB |
Output is correct |
3 |
Correct |
41 ms |
111440 KB |
Output is correct |
4 |
Correct |
43 ms |
111184 KB |
Output is correct |
5 |
Correct |
43 ms |
107348 KB |
Output is correct |
6 |
Correct |
29 ms |
78516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16988 KB |
Output is correct |
2 |
Correct |
6 ms |
17032 KB |
Output is correct |
3 |
Correct |
6 ms |
16988 KB |
Output is correct |
4 |
Correct |
7 ms |
16856 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
2652 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
2652 KB |
Output is correct |
9 |
Correct |
3 ms |
6748 KB |
Output is correct |
10 |
Correct |
3 ms |
6792 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
3 ms |
6748 KB |
Output is correct |
13 |
Correct |
3 ms |
6748 KB |
Output is correct |
14 |
Correct |
37 ms |
96848 KB |
Output is correct |
15 |
Correct |
31 ms |
84564 KB |
Output is correct |
16 |
Correct |
41 ms |
111440 KB |
Output is correct |
17 |
Correct |
43 ms |
111184 KB |
Output is correct |
18 |
Correct |
43 ms |
107348 KB |
Output is correct |
19 |
Correct |
29 ms |
78516 KB |
Output is correct |
20 |
Correct |
7 ms |
16988 KB |
Output is correct |
21 |
Correct |
6 ms |
17032 KB |
Output is correct |
22 |
Correct |
6 ms |
16988 KB |
Output is correct |
23 |
Correct |
7 ms |
16856 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
29 ms |
78428 KB |
Output is correct |
26 |
Correct |
33 ms |
90716 KB |
Output is correct |
27 |
Correct |
28 ms |
60500 KB |
Output is correct |
28 |
Correct |
33 ms |
90708 KB |
Output is correct |
29 |
Correct |
36 ms |
92764 KB |
Output is correct |
30 |
Correct |
42 ms |
111360 KB |
Output is correct |