#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m, k;
const int maxn = 310;
const int inf = maxn * maxn + 400;
int a[maxn];
int az = 0;
int b[maxn];
int dp[maxn][inf];
int sol = inf;
int main(){
//memset(dp, -inf, sizeof(dp));
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
int r = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
az += a[i];
if (a[i] < k){
r = 1;
}
}
for (int i = 0; i < m; i++){
cin >> b[i];
}
for (int i = 0; i <= m; i++){
for (int j = 0; j < maxn * maxn; j++){
dp[i][j] = -inf;
}
}
dp[m][0] = 0;
for (int i = m - 1; i >= 0; i--){
for (int j = maxn * maxn; j >= 0; j--){
//dp[i][j] = dp[i + 1][j - b[i]] + min(n, b[i]);
dp[i][j] = dp[i + 1][j];
dp[i][j + b[i]] = max(dp[i][j + b[i]], dp[i + 1][j] + min(n, b[i]));
}
}
//cout << az << endl;
for (int j = maxn * maxn; j >= 0; j--){
if (dp[0][j] >= k * n && j >= az){
sol = min(sol, j);
}
}
if (r == 0 && sol != inf){
cout << sol - az;
}
else {
cout << "Impossible";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
2 ms |
1516 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1516 KB |
Output is correct |
5 |
Correct |
2 ms |
1516 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
2 ms |
1516 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1516 KB |
Output is correct |
5 |
Correct |
2 ms |
1516 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
9 |
Correct |
7 ms |
6380 KB |
Output is correct |
10 |
Correct |
7 ms |
6380 KB |
Output is correct |
11 |
Correct |
7 ms |
6252 KB |
Output is correct |
12 |
Correct |
7 ms |
6400 KB |
Output is correct |
13 |
Correct |
7 ms |
6380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
99 ms |
99308 KB |
Output is correct |
2 |
Correct |
85 ms |
86144 KB |
Output is correct |
3 |
Correct |
122 ms |
114028 KB |
Output is correct |
4 |
Correct |
122 ms |
114048 KB |
Output is correct |
5 |
Correct |
108 ms |
110368 KB |
Output is correct |
6 |
Correct |
76 ms |
79340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
16 ms |
15852 KB |
Output is correct |
2 |
Correct |
16 ms |
15852 KB |
Output is correct |
3 |
Correct |
16 ms |
15852 KB |
Output is correct |
4 |
Correct |
16 ms |
15852 KB |
Output is correct |
5 |
Correct |
16 ms |
15852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1516 KB |
Output is correct |
2 |
Correct |
2 ms |
1516 KB |
Output is correct |
3 |
Correct |
2 ms |
1516 KB |
Output is correct |
4 |
Correct |
2 ms |
1516 KB |
Output is correct |
5 |
Correct |
2 ms |
1516 KB |
Output is correct |
6 |
Correct |
2 ms |
1516 KB |
Output is correct |
7 |
Correct |
2 ms |
1516 KB |
Output is correct |
8 |
Correct |
2 ms |
1516 KB |
Output is correct |
9 |
Correct |
7 ms |
6380 KB |
Output is correct |
10 |
Correct |
7 ms |
6380 KB |
Output is correct |
11 |
Correct |
7 ms |
6252 KB |
Output is correct |
12 |
Correct |
7 ms |
6400 KB |
Output is correct |
13 |
Correct |
7 ms |
6380 KB |
Output is correct |
14 |
Correct |
99 ms |
99308 KB |
Output is correct |
15 |
Correct |
85 ms |
86144 KB |
Output is correct |
16 |
Correct |
122 ms |
114028 KB |
Output is correct |
17 |
Correct |
122 ms |
114048 KB |
Output is correct |
18 |
Correct |
108 ms |
110368 KB |
Output is correct |
19 |
Correct |
76 ms |
79340 KB |
Output is correct |
20 |
Correct |
16 ms |
15852 KB |
Output is correct |
21 |
Correct |
16 ms |
15852 KB |
Output is correct |
22 |
Correct |
16 ms |
15852 KB |
Output is correct |
23 |
Correct |
16 ms |
15852 KB |
Output is correct |
24 |
Correct |
16 ms |
15852 KB |
Output is correct |
25 |
Correct |
78 ms |
80108 KB |
Output is correct |
26 |
Correct |
89 ms |
92524 KB |
Output is correct |
27 |
Correct |
59 ms |
61164 KB |
Output is correct |
28 |
Correct |
90 ms |
93036 KB |
Output is correct |
29 |
Correct |
108 ms |
95084 KB |
Output is correct |
30 |
Correct |
111 ms |
114028 KB |
Output is correct |