#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int n, m, k;
int dp[333*333];
int a[333];
int b[333];
void solve() {
cin >> n >> m >> k;
int s = 0;
for(int i = 1; i <= n; i++) {
cin >> a[i];
if(a[i] < k) {
cout << "Impossible\n";
return;
}
s += a[i];
}
int t = 0;
for(int i = 1; i <= m; i++) {
cin >> b[i];
t += b[i];
}
for(int i = 1; i <= t; i++) {
dp[i] = -inf;
}
for(int i=1; i <= m; i++) {
int c = min(b[i], n);
for(int j = t; j >= b[i]; j--) {
dp[j] = max(dp[j-b[i]] + c, dp[j]);
}
}
for(int i = s; i <= t; i++) {
if(dp[i] >= n * k) {
cout << i-s << "\n";
return;
}
}
cout << "Impossible";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
for(int i = 0; i < t; i++) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
648 KB |
Output is correct |
2 |
Correct |
10 ms |
464 KB |
Output is correct |
3 |
Correct |
11 ms |
604 KB |
Output is correct |
4 |
Correct |
18 ms |
604 KB |
Output is correct |
5 |
Correct |
18 ms |
796 KB |
Output is correct |
6 |
Correct |
8 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
604 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
464 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
13 ms |
648 KB |
Output is correct |
15 |
Correct |
10 ms |
464 KB |
Output is correct |
16 |
Correct |
11 ms |
604 KB |
Output is correct |
17 |
Correct |
18 ms |
604 KB |
Output is correct |
18 |
Correct |
18 ms |
796 KB |
Output is correct |
19 |
Correct |
8 ms |
600 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
604 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
9 ms |
600 KB |
Output is correct |
26 |
Correct |
12 ms |
716 KB |
Output is correct |
27 |
Correct |
5 ms |
600 KB |
Output is correct |
28 |
Correct |
10 ms |
672 KB |
Output is correct |
29 |
Correct |
13 ms |
604 KB |
Output is correct |
30 |
Correct |
21 ms |
604 KB |
Output is correct |