#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define SZ(x) ((int)(x).size())
#define all(x) x.begin(), x.end()
#define debug(x) cout << #x << ": " << x << " "
#define nl cout << "\n"
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define per(i, a, b) for(int i = (a); i >= (b); i--)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int INF = 1e9;
const int MAXN = 300+10;
int N, M, K, a[MAXN], b[MAXN], memo[MAXN][MAXN * MAXN];
void Impossible(){
cout << "Impossible";
}
int f(int i, int sum){
if(i == M){
if(sum == 0) return 0;
else return INF;
}
int& ans = memo[i][sum];
if(ans != INF){
return ans;
}
ans = f(i + 1, sum);
if(sum - b[i] >= 0){
ans = min(ans, f(i + 1, sum - b[i]) - min(N, b[i]));
}
return ans;
}
void solve(){
cin >> N >> M >> K;
rep(i, 0, N) cin >> a[i];
rep(i, 0, M) cin >> b[i];
int s = 0;
rep(i, 0, N){
if(a[i] < K) Impossible();
s += a[i];
}
int sb = 0;
rep(i, 0, M){
sb += b[i];
}
if(s > sb) Impossible();
if(M < K) Impossible();
rep(i, 0, MAXN){
rep(j, 0, MAXN * MAXN){
memo[i][j] = INF;
}
}
for(int ans = 0; ans + s <= sb; ans++){
if(f(0, ans + s) <= 0){
cout << ans; return;
}
}
Impossible();
}
int main(){
ios_base::sync_with_stdio(false), cin.tie(nullptr);
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
116804 KB |
Output is correct |
2 |
Correct |
64 ms |
116876 KB |
Output is correct |
3 |
Correct |
60 ms |
116832 KB |
Output is correct |
4 |
Incorrect |
60 ms |
116852 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
116804 KB |
Output is correct |
2 |
Correct |
64 ms |
116876 KB |
Output is correct |
3 |
Correct |
60 ms |
116832 KB |
Output is correct |
4 |
Incorrect |
60 ms |
116852 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
134 ms |
116916 KB |
Output is correct |
2 |
Correct |
144 ms |
116900 KB |
Output is correct |
3 |
Correct |
173 ms |
116916 KB |
Output is correct |
4 |
Correct |
279 ms |
117032 KB |
Output is correct |
5 |
Incorrect |
61 ms |
116812 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
65 ms |
116844 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
62 ms |
116804 KB |
Output is correct |
2 |
Correct |
64 ms |
116876 KB |
Output is correct |
3 |
Correct |
60 ms |
116832 KB |
Output is correct |
4 |
Incorrect |
60 ms |
116852 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |