제출 #1130155

#제출 시각아이디문제언어결과실행 시간메모리
1130155vladiliusKitchen (BOI19_kitchen)C++20
52 / 100
1052 ms2140 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin>>n>>m>>k; vector<int> a(n + 1); for (int i = 1; i <= n; i++){ cin>>a[i]; } vector<int> b(m); for (int i = 0; i < m; i++){ cin>>b[i]; } int S1 = 0; for (int i = 1; i <= n; i++){ if (a[i] < k){ cout<<"Impossible"<<"\n"; return 0; } S1 += a[i]; } int S2 = k * n; sort(b.begin(), b.end()); int j = 0; while (j < m && b[j] < n) j++; const int A = 300 * m; vector<bool> sm(A + 1); sm[0] = 1; for (int i = 0; i < j; i++){ for (int t = A; t >= 0; t--){ if (sm[t]){ sm[t + b[i]] = 1; } } } vector<int> all; for (int i = 0; i <= A; i++){ if (sm[i]) all.pb(i); } int M = m - j; vector<vector<bool>> can(M + 1, vector<bool>(A + 1)); can[0][0] = 1; for (int i = j; i < m; i++){ for (int t = M; t >= 0; t--){ for (int x = A; x >= 0; x--){ if (can[t][x]){ can[t + 1][x + b[i]] = 1; } } } } int out = 1e9; for (int cc = 0; cc <= M; cc++){ vector<int> low(A + 1, -1); low[A] = (can[cc][A]) ? A : -1; for (int i = A - 1; i >= 0; i--){ if (!can[cc][i]){ low[i] = low[i + 1]; } else { low[i] = i; } } for (int sl: all){ if (sl >= (S2 - n * cc)){ int x = low[max(0, S1 - sl)]; if (x != -1){ out = min(out, sl + x); } } } } if (out == 1e9){ cout<<"Impossible"<<"\n"; } else { cout<<out - S1<<"\n"; } }
#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...