#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 32768
#define INF 100000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
int main()
{
int n, m, k;
cin >> n >> m >> k;
int M = m*300;
int N = max(k,40);
pair<bool,int> dp[M+3][N+3] = {};
int meal[n], chef[m];
dp[0][0].first = 1;
long long sum = 0;
bool ok = true;
for(int i = 0; i < n; i++)
{
cin >> meal[i];
if(meal[i] < k)
ok = false;
sum += meal[i];
}
for(int q = 0; q < m; q++)
{
cin >> chef[q];
int x = chef[q];
for(int i = M-1; i >= x; i--)
{
for(int j = 1; j < N; j++)
{
if(dp[i-x][j-1].first)
{
dp[i][j].first = 1;
if(x >= k)
dp[i][j].second += dp[i-x][j-1].second+1;
else
dp[i][j].second = dp[i-x][j-1].second;
}
}
}
}
if(m < k || ok == false)
{
cout << "Impossible";
return 0;
}
for(int i = sum; i < M; i++)
{
for(int j = k; j < N; j++)
{
if(dp[i][j].first == 1 && dp[i][j].second >= k)
{
cout << i-sum;
return 0;
}
}
}
cout << "Impossible";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
1748 KB |
Output is correct |
10 |
Correct |
3 ms |
1748 KB |
Output is correct |
11 |
Correct |
5 ms |
1748 KB |
Output is correct |
12 |
Correct |
3 ms |
1748 KB |
Output is correct |
13 |
Correct |
4 ms |
1748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
1092 ms |
26620 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
24 ms |
4336 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
0 ms |
468 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
4 ms |
1748 KB |
Output is correct |
10 |
Correct |
3 ms |
1748 KB |
Output is correct |
11 |
Correct |
5 ms |
1748 KB |
Output is correct |
12 |
Correct |
3 ms |
1748 KB |
Output is correct |
13 |
Correct |
4 ms |
1748 KB |
Output is correct |
14 |
Execution timed out |
1092 ms |
26620 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |