#include <bits/stdc++.h>
#define ll long long
#define ldb long double
#define endl '\n'
#define For(i,l,r) for(int i=l;i<=r;i++)
#define ForD(i,r,l) for(int i=r;i>=l;i--)
#define REP(i,l,r) For(i,l,r-1)
#define PER(i,r,l) ForD(i,r-1,l)
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(),x.end()
#define All(x,n) x+1,x+1+n
#define Alll(x,n) x,x+n
#define sz(x) (signed)x.size()
#define unq(x) x.resize(unique(all(x))-x.begin())
#define mpa make_pair
#ifdef NCGM
#include"debug.h"
#else
#define debug(...) "fr";
#endif
using namespace std;
const int N=303;
int n,m,k;
int a[N],b[N],f[N][N*N];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m >> k;
int tmp=0;
For(i,1,n) {
cin >> a[i];
tmp+=a[i];
}
For(i,1,m) cin >> b[i];
For(i,1,n)
if (a[i]<k) return !(cout << "Impossible");
For(i,0,n)
For(j,0,max(m,n)*300) f[i][j]=-2e9;
f[0][0]=0;
For(i,1,m)
For(j,0,max(m,n)*300) {
f[i][j]=f[i-1][j];
if (j>=b[i]) f[i][j]=max(f[i][j],f[i-1][j-b[i]]+min(b[i],n));
}
int ans=2e9;
For(j,tmp,max(m,n)*300)
if (f[m][j]>=n*k) ans=min(ans,j-tmp);
if (ans>=2e9) cout << "Impossible";
else cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
47 ms |
107604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
47 ms |
107604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
7004 KB |
Output is correct |
13 |
Correct |
44 ms |
107548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
105808 KB |
Output is correct |
2 |
Correct |
75 ms |
105552 KB |
Output is correct |
3 |
Correct |
81 ms |
107492 KB |
Output is correct |
4 |
Correct |
78 ms |
107616 KB |
Output is correct |
5 |
Correct |
85 ms |
107600 KB |
Output is correct |
6 |
Correct |
70 ms |
105556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
7772 KB |
Output is correct |
2 |
Correct |
2 ms |
7772 KB |
Output is correct |
3 |
Correct |
2 ms |
7696 KB |
Output is correct |
4 |
Correct |
2 ms |
7772 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
47 ms |
107604 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
6488 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6492 KB |
Output is correct |
12 |
Correct |
1 ms |
7004 KB |
Output is correct |
13 |
Correct |
44 ms |
107548 KB |
Output is correct |
14 |
Correct |
66 ms |
105808 KB |
Output is correct |
15 |
Correct |
75 ms |
105552 KB |
Output is correct |
16 |
Correct |
81 ms |
107492 KB |
Output is correct |
17 |
Correct |
78 ms |
107616 KB |
Output is correct |
18 |
Correct |
85 ms |
107600 KB |
Output is correct |
19 |
Correct |
70 ms |
105556 KB |
Output is correct |
20 |
Correct |
2 ms |
7772 KB |
Output is correct |
21 |
Correct |
2 ms |
7772 KB |
Output is correct |
22 |
Correct |
2 ms |
7696 KB |
Output is correct |
23 |
Correct |
2 ms |
7772 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
39 ms |
55108 KB |
Output is correct |
26 |
Correct |
51 ms |
72532 KB |
Output is correct |
27 |
Correct |
24 ms |
34140 KB |
Output is correct |
28 |
Correct |
60 ms |
72716 KB |
Output is correct |
29 |
Correct |
60 ms |
76176 KB |
Output is correct |
30 |
Correct |
92 ms |
107604 KB |
Output is correct |