제출 #717009

#제출 시각아이디문제언어결과실행 시간메모리
717009AmirAli_H1Kitchen (BOI19_kitchen)C++17
100 / 100
176 ms219520 KiB
// In the name of Allah #include <bits/stdc++.h> using namespace std; typedef long long int ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; #define all(x) (x).begin(),(x).end() #define len(x) ((ll) (x).size()) #define F first #define S second #define pb push_back #define sep ' ' #define endl '\n' #define Mp make_pair #define debug(x) cerr << #x << ": " << x << endl; #define kill(x) cout << x << '\n', exit(0); #define set_dec(x) cout << fixed << setprecision(x); #define file_io(x,y) freopen(x, "r", stdin); freopen(y, "w", stdout); int n, m, k; const int maxn = 300 + 5; const int oo = 1e9; int a[maxn], b[maxn]; pii dp[maxn][maxn * maxn]; pii GX(pii val, int x) { if (val.F >= oo) return Mp(oo, 0); if (x >= n) { val.F--; } else { val.S = x + val.S; val.F -= (val.S / n); val.S %= n; } return val; } pii cmp(pii a, pii b) { if (a.F >= oo && b.F >= oo) return Mp(oo, 0); else if (a.F >= oo) return b; else if (b.F >= oo) return a; int x = a.F * n - a.S, y = b.F * n - b.S; if (x < y) return a; else return b; } int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); 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 sm = 0; for (int i = 1; i <= n; i++) { if (a[i] < k) kill("Impossible"); sm += a[i]; } for (int i = 0; i <= m; i++) { dp[i][0] = Mp(k, 0); for (int val = 1; val < maxn * maxn; val++) { if (i == 0) dp[i][val] = Mp(oo, 0); else { if (val - b[i] >= 0) { dp[i][val] = cmp(dp[i - 1][val], GX(dp[i - 1][val - b[i]], b[i])); } else dp[i][val] = dp[i - 1][val]; } } } for (int val = sm; val < maxn * maxn; val++) { if (dp[m][val].F <= 0) { kill(val - sm); } } cout << "Impossible" << endl; return 0; }
#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...