제출 #648501

#제출 시각아이디문제언어결과실행 시간메모리
648501LoboKitchen (BOI19_kitchen)C++17
0 / 100
67 ms136644 KiB
#include<bits/stdc++.h> using namespace std; const long long inf = (long long) 1e18 + 10; const int inf1 = (int) 1e9 + 10; #define int long long #define dbl long double #define endl '\n' #define sc second #define fr first #define mp make_pair #define pb push_back #define all(x) x.begin(), x.end() const int maxn = 303; int n, m, k, a[maxn], b[maxn]; int m1, m2, b1[maxn], b2[maxn], mv1, mv2; int dp1[maxn][maxn*maxn], dp2[maxn][maxn*maxn]; void solve() { cin >> n >> m >> k; for(int i = 1; i <= n; i++) { cin >> a[i]; } for(int i = 1; i <= m; i++) { cin >> b[i]; } int sma = 0; for(int i = 1; i <= n; i++) { sma+= a[i]; if(a[i] < k) { cout << "Impossible" << endl; return; } } if(m < k) { cout << "Impossible" << endl; return; } for(int i = 1; i <= m; i++) { if(b[i] <= k) { b1[++m1] = b[i]; mv1+= b[i]; } else { b2[++m2] = b[i]; mv2+= b[i]; } } dp1[0][0] = 1; for(int i = 1; i <= m1; i++) { for(int j = 0; j <= mv1; j++) { dp1[i][j] = dp1[i-1][j]; if(j-b1[i] >= 0) dp1[i][j]|= dp1[i-1][j-b1[i]]; } } dp2[0][0] = 0; for(int i = 1; i <= mv2; i++) dp2[0][i] = -1; for(int i = 1; i <= m2; i++) { for(int j = 0; j <= mv2; j++) { dp2[i][j] = dp2[i-1][j]; if(j-b2[i] >= 0) dp2[i][j] = max(dp2[i][j],dp2[i-1][j-b2[i]]+1); } } int ans = inf; for(int i = 0; i <= mv1; i++) { if(dp1[m1][i] == 0) continue; for(int j = 0; j <= mv2; j++) { if(dp2[m2][j] != -1 && i+j >= sma && i+dp2[m2][j]*k >= n*k) { ans = min(ans, i+j-sma); } } } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); // freopen("in.in", "r", stdin); // freopen("out.out", "w", stdout); int tt = 1; // cin >> tt; while(tt--) { solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...