#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 = 1e3 + 5;
ll n, m, k, sum, chefsum;
ll a[N], chef[N];
ll dp[N][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);
for(ll i = 1; i <= m; ++i)
cin >> chef[i], chefsum += chef[i];
sort(chef + 1, chef + m + 1);
if(m < k || a[1] < k)
{
cout << "Impossible" << endll;
return 0;
}
dp[0][0] = 1;
for(ll i = 1; i <= m; ++i)
{
for(ll j = chef[i]; j <= N; ++j)
{
if(dp[i - 1][j - chef[i]])
dp[i][j] = true;
}
}
ll ans = 1e18;
for(ll i = k; i <= m; ++i)
{
for(ll j = sum; j <= N; ++j)
{
if(dp[i][j])
{
ans = min(ans, j - sum);
break;
}
}
}
cout << ans << endll;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |