#include <bits/stdc++.h>
#include <fstream>
#define endl '\n'
#define mod 1668223877717
#define INF -100000000000000000
//#define ll long long
//#define cin fin
//#define cout fout
using namespace std;
//ofstream fout("convention.out");
//ifstream fin("convention.in");
const int M = 9e4 + 5;
int n, m, k;
pair<bool,long long> dp[M] = {};
void add(int x)
{
for(int i = M-1; i >= x; i--)
{
if(dp[i-x].first == 1)
{
dp[i].first = 1;
dp[i].second = max(dp[i].second,dp[i-x].second+min(n,x));
}
}
}
int main()
{
ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
cin >> n >> m >> k;
int meal[n], chef[m];
long long sum = 0;
bool ok = true;
dp[0].first = 1;
for(int i = 0; i < n; i++)
{
cin >> meal[i];
if(meal[i] < k)
ok = false;
sum += meal[i];
}
for(int i = 0; i < m; i++)
{
cin >> chef[i];
add(chef[i]);
}
if(ok == false)
{
cout << "Impossible";
return 0;
}
for(int i = sum; i < M; i++)
{
if(dp[i].second >= n*k)
{
cout << i-sum;
return 0;
}
}
cout << "Impossible";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
27 ms |
1316 KB |
Output is correct |
2 |
Correct |
32 ms |
1196 KB |
Output is correct |
3 |
Correct |
49 ms |
972 KB |
Output is correct |
4 |
Correct |
33 ms |
1484 KB |
Output is correct |
5 |
Correct |
31 ms |
1636 KB |
Output is correct |
6 |
Correct |
23 ms |
1096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
340 KB |
Output is correct |
3 |
Correct |
4 ms |
340 KB |
Output is correct |
4 |
Correct |
5 ms |
340 KB |
Output is correct |
5 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
336 KB |
Output is correct |
11 |
Correct |
3 ms |
212 KB |
Output is correct |
12 |
Correct |
2 ms |
212 KB |
Output is correct |
13 |
Correct |
2 ms |
340 KB |
Output is correct |
14 |
Correct |
27 ms |
1316 KB |
Output is correct |
15 |
Correct |
32 ms |
1196 KB |
Output is correct |
16 |
Correct |
49 ms |
972 KB |
Output is correct |
17 |
Correct |
33 ms |
1484 KB |
Output is correct |
18 |
Correct |
31 ms |
1636 KB |
Output is correct |
19 |
Correct |
23 ms |
1096 KB |
Output is correct |
20 |
Correct |
5 ms |
340 KB |
Output is correct |
21 |
Correct |
5 ms |
340 KB |
Output is correct |
22 |
Correct |
4 ms |
340 KB |
Output is correct |
23 |
Correct |
5 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
24 ms |
1236 KB |
Output is correct |
26 |
Correct |
29 ms |
1296 KB |
Output is correct |
27 |
Correct |
20 ms |
740 KB |
Output is correct |
28 |
Correct |
26 ms |
1100 KB |
Output is correct |
29 |
Correct |
30 ms |
1332 KB |
Output is correct |
30 |
Correct |
35 ms |
1540 KB |
Output is correct |