#include<bits/stdc++.h>
#define pi 3.141592653589793238
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#define MOD 1000000007
#define INF 999999999999999999
#define pb push_back
#define ff first
#define ss second
#define mt make_tuple
#define ll long long
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const int N = 3e2 + 2;
ll dp[N][N][N];
void chmin(ll& a, ll b){
a = min(a, b);
}
int main() {
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
fast;
ll T = 1, i, j;
//cin >> T;
while (T--) {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a(n), b(m);
bool flag = true;
ll sum = 0;
ll sa = 0;
for(i = 0; i < n; i++){
cin >> a[i];
if(a[i] < k){
flag = false;
}
sum += a[i];
}
sa = sum;
for(i = 0; i < m; i++){
cin >> b[i];
sum -= b[i];
}
if(sum > 0){
flag = false;
}
if(m < k){
flag = false;
}
if(!flag){
cout << "Impossible\n";
return 0;
}
for(i = 0; i < N; i++){
for(j = 0; j < N; j++){
for(ll jj = 0; jj < N; jj++){
dp[i][j][jj] = INF;
}
}
}
dp[0][0][0] = 0;
for(i = 0; i < m; i++){
ll B = min(b[i], n);
for(ll x = 0; x < n; x++){
for(ll done = 0; done <= k; done++){
if(dp[i][x][done] == INF){
continue;
}
if(x + B < n){
chmin(dp[i + 1][x + B][done], dp[i][x][done] + b[i]);
//cout << dp[i + 1][x + B][done] << " " << i + 1 << " " << x + B << " " << done << endl;
}
else{
chmin(dp[i + 1][x + B - n][done + 1], dp[i][x][done] + b[i]);
//cout << dp[i + 1][x + B - n][done + 1] << " " << i + 1 << " " << x + B - n << " " << done + 1 << endl;
}
}
}
}
// if(dp[m][0][k] == INF){
// cout << "Impossible\n";
// return 0;
// }
ll ans = dp[m][0][k] - sa;
for(i = 0; i < n; i++){
chmin(ans, dp[m][i][k] - sa);
}
if(ans >= 1000000){
cout << "Impossible\n";
return 0;
}
cout << ans << endl;
}
return 0;
}
Compilation message
kitchen.cpp:4: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
4 | #pragma GCC optimization ("O3")
|
kitchen.cpp:5: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
5 | #pragma GCC optimization ("unroll-loops")
|
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
215916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
215916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
128 ms |
216004 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
131 ms |
215916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
125 ms |
215916 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |