#include <iostream>
#include <vector>
using namespace std;
int main(){
int n, m ,k;
cin >> n >> m >> k;
int suma = 0;
int mini = 1<<29;
vector <int> a(n);
for (int i = 0; i < n; i++){
cin >> a[i];
mini = min(mini,a[i]);
suma += a[i];
}
int sumb = 0;
vector <int> b(m);
for (int i = 0; i < m; i++){
cin >> b[i];
}
if (mini < k){
cout << "Impossible";
return 0;
}
if (k > m){
cout << "Impossible";
return 0;
}
vector <int> dp(90001,-1*(1<<29));
dp[0] = 0;
for (int i = 0; i < m; i++){
int dod = b[i];
sumb += dod;
for (int j = sumb; j >= 0; j--){
dp[j+dod] = max(dp[j+dod], dp[j] + min(dod,n));
}
}
for (int i = suma; i <= sumb; i++){
//cout << dp[i] << endl;
if (dp[i] >= n*k){
cout << i - suma;
return 0;
}
}
cout << "Impossible";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
760 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
632 KB |
Output is correct |
2 |
Correct |
9 ms |
632 KB |
Output is correct |
3 |
Correct |
10 ms |
632 KB |
Output is correct |
4 |
Correct |
14 ms |
632 KB |
Output is correct |
5 |
Correct |
14 ms |
632 KB |
Output is correct |
6 |
Correct |
8 ms |
632 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
760 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
632 KB |
Output is correct |
2 |
Correct |
2 ms |
632 KB |
Output is correct |
3 |
Correct |
2 ms |
632 KB |
Output is correct |
4 |
Correct |
2 ms |
632 KB |
Output is correct |
5 |
Correct |
2 ms |
760 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
760 KB |
Output is correct |
9 |
Correct |
2 ms |
760 KB |
Output is correct |
10 |
Correct |
2 ms |
632 KB |
Output is correct |
11 |
Correct |
2 ms |
632 KB |
Output is correct |
12 |
Correct |
2 ms |
632 KB |
Output is correct |
13 |
Correct |
2 ms |
760 KB |
Output is correct |
14 |
Correct |
11 ms |
632 KB |
Output is correct |
15 |
Correct |
9 ms |
632 KB |
Output is correct |
16 |
Correct |
10 ms |
632 KB |
Output is correct |
17 |
Correct |
14 ms |
632 KB |
Output is correct |
18 |
Correct |
14 ms |
632 KB |
Output is correct |
19 |
Correct |
8 ms |
632 KB |
Output is correct |
20 |
Correct |
2 ms |
632 KB |
Output is correct |
21 |
Correct |
2 ms |
632 KB |
Output is correct |
22 |
Correct |
2 ms |
760 KB |
Output is correct |
23 |
Correct |
2 ms |
632 KB |
Output is correct |
24 |
Correct |
2 ms |
256 KB |
Output is correct |
25 |
Correct |
8 ms |
632 KB |
Output is correct |
26 |
Correct |
10 ms |
636 KB |
Output is correct |
27 |
Correct |
5 ms |
632 KB |
Output is correct |
28 |
Correct |
9 ms |
632 KB |
Output is correct |
29 |
Correct |
11 ms |
728 KB |
Output is correct |
30 |
Correct |
15 ms |
632 KB |
Output is correct |