Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- #define pb emplace_back
- #define AI(i) begin(i), end(i)
- template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
- template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
- #ifdef KEV
- #define DE(args...) kout("[ " + string(#args) + " ] = ", args)
- void kout() { cerr << endl; }
- template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
- template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
- #else
- #define DE(...) 0
- #define debug(...) 0
- #endif
- // My bug list :
- // integer overflow
- // 0based, 1based forgotten
- // index out of bound
- // n, m, i, j typo
- // some cases are missing
- const int MAX_N = 510;
- int n, c, p[MAX_N], q[MAX_N], a[MAX_N], b[MAX_N], ext[MAX_N];
- int cnt[MAX_N];
- int push(int x, int ind) {
- fill(cnt, cnt + n, 0);
- int ret = 0;
- while (x--) {
- int pos = -1, more = -1;
- for (int j = ind+1;j < n;++j) {
- if (cnt[j] == c) continue;
- if (chmax(more, ext[j]))
- pos = j;
- }
- if (pos == -1) break;
- ++ret;
- --ext[pos], ++cnt[pos];
- }
- return ret;
- }
- int solve() {
- int res = 0;
- for (int i = n-1;i >= 0;--i) {
- int x = min(p[i], a[i]), y = min(q[i], b[i]);
- res += x + y;
- p[i] -= x, a[i] -= x;
- q[i] -= y, b[i] -= y;
- ext[i] = a[i] + b[i];
- int v = push(p[i] + q[i], i);
- res += v;
- }
- return res;
- }
- int32_t main() {
- ios_base::sync_with_stdio(0), cin.tie(0);
- cin >> n >> c;
- for (int i = 0;i < n;++i) cin >> p[i];
- for (int i = 0;i < n;++i) cin >> q[i];
- for (int i = 0;i < n;++i) cin >> a[i];
- for (int i = 0;i < n;++i) cin >> b[i];
- cout << solve() << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement