#include <bits/stdc++.h>
/// author: LilPluton auuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu
#define OPT ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define intt long long
#define ll long long
#define pb push_back
#define arr array
#define vll vector<int>
#define fi first
#define se second
#define rep(i,j,k) for(int i = j; i <= k; ++i)
#define all(a) a.begin(),a.end()
#define pii pair<int,int>
#define endll '\n'
using namespace std;
const ll INF = 1e18;
const int N = 305 * 305;
ll n, m, k, sum, chefsum;
ll a[N], chef[N];
ll dp[N];
signed main()
{
cin >> n >> m >> k;
for(ll i = 1; i <= n; ++i)
cin >> a[i], sum += a[i];
sort(a + 1, a + n + 1);
if(a[1] < k || m < k)
{
cout << "Impossible" << endll;
return 0;
}
for (int i = 1; i <= m; ++i) {
cin >> chef[i];
for (int j = N; j >= chef[i]; --j) {
if (j - chef[i] == 0 || dp[j - chef[i]]) {
dp[j] = 1;
}
}
}
for(ll i = sum; i <= N; ++i)
{
if(dp[i])
{
cout << i - sum << endll;
return 0;
}
}
cout << "Impossible" << endll;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
860 KB |
Output is correct |
2 |
Correct |
14 ms |
860 KB |
Output is correct |
3 |
Correct |
17 ms |
696 KB |
Output is correct |
4 |
Correct |
18 ms |
856 KB |
Output is correct |
5 |
Correct |
26 ms |
860 KB |
Output is correct |
6 |
Correct |
14 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
444 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |