#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
#define endl "\n"
int mod=1e9+7;
const int N=2e5+5;
template<class x>
using ordered_multiset = tree<x, null_type,less_equal<x>, rb_tree_tag,tree_order_statistics_node_update>;
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//freopen(".in", "r", stdin); freopen(".out", "w", stdout);
int n,m,k; cin>>n>>m>>k;
int a[n],b[m];
int suma=0;
bool bl=true;
for (int &i:a) {
cin>>i;
if (i<k || m<k) bl=false;
suma+=i;
}
for (int &i:b) cin>>i;
if (!bl) {
cout<<"Impossible"; return 0;
}
int dp[90005];
for (int i=0;i<=90000;i++) dp[i]=-1e18;
dp[0]=0;
for (int i=0;i<m;i++) {
for (int j=90000;j>=b[i];j--) {
dp[j]=max(dp[j],dp[j-b[i]]+min(n,b[i]));
}
}
for (int i=suma;i<=90000;i++) {
if (dp[i]>=k*n) {
cout<<i-suma; return 0;
}
}
cout<<"Impossible";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1020 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1020 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1020 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1020 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
924 KB |
Output is correct |
13 |
Correct |
2 ms |
1020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
980 KB |
Output is correct |
2 |
Correct |
19 ms |
1024 KB |
Output is correct |
3 |
Correct |
26 ms |
1020 KB |
Output is correct |
4 |
Correct |
27 ms |
1024 KB |
Output is correct |
5 |
Correct |
26 ms |
1024 KB |
Output is correct |
6 |
Correct |
17 ms |
1024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
980 KB |
Output is correct |
2 |
Correct |
4 ms |
980 KB |
Output is correct |
3 |
Correct |
4 ms |
924 KB |
Output is correct |
4 |
Correct |
4 ms |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
980 KB |
Output is correct |
2 |
Correct |
1 ms |
980 KB |
Output is correct |
3 |
Correct |
1 ms |
980 KB |
Output is correct |
4 |
Correct |
1 ms |
1020 KB |
Output is correct |
5 |
Correct |
1 ms |
980 KB |
Output is correct |
6 |
Correct |
1 ms |
980 KB |
Output is correct |
7 |
Correct |
1 ms |
1020 KB |
Output is correct |
8 |
Correct |
1 ms |
980 KB |
Output is correct |
9 |
Correct |
2 ms |
980 KB |
Output is correct |
10 |
Correct |
2 ms |
980 KB |
Output is correct |
11 |
Correct |
2 ms |
980 KB |
Output is correct |
12 |
Correct |
2 ms |
924 KB |
Output is correct |
13 |
Correct |
2 ms |
1020 KB |
Output is correct |
14 |
Correct |
21 ms |
980 KB |
Output is correct |
15 |
Correct |
19 ms |
1024 KB |
Output is correct |
16 |
Correct |
26 ms |
1020 KB |
Output is correct |
17 |
Correct |
27 ms |
1024 KB |
Output is correct |
18 |
Correct |
26 ms |
1024 KB |
Output is correct |
19 |
Correct |
17 ms |
1024 KB |
Output is correct |
20 |
Correct |
4 ms |
980 KB |
Output is correct |
21 |
Correct |
4 ms |
980 KB |
Output is correct |
22 |
Correct |
4 ms |
924 KB |
Output is correct |
23 |
Correct |
4 ms |
980 KB |
Output is correct |
24 |
Correct |
1 ms |
980 KB |
Output is correct |
25 |
Correct |
17 ms |
1024 KB |
Output is correct |
26 |
Correct |
19 ms |
1028 KB |
Output is correct |
27 |
Correct |
14 ms |
1028 KB |
Output is correct |
28 |
Correct |
22 ms |
1024 KB |
Output is correct |
29 |
Correct |
20 ms |
1016 KB |
Output is correct |
30 |
Correct |
24 ms |
980 KB |
Output is correct |