#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define ll long long int
using namespace std;
int main() {
ll n; cin >> n; ll r = 0;
set<ll> x; map<ll,ll> cnt;
for (int i = 0; i < n; i++) {
ll xi; cin >> xi;
if (xi == 0) continue;
x.insert(i); cnt[i] = xi;
}
deque<ll> y;
for (int i = 0; i < n; i++) {
ll yi; cin >> yi;
while (yi--) {
if (x.lower_bound(i) == x.begin()) {
y.push_front(i); continue;
}
r++; cnt[*prev(x.lower_bound(i))]--;
if (cnt[*prev(x.lower_bound(i))] == 0) {
x.erase(prev(x.lower_bound(i)));
}
}
}
deque<ll> nx;
for (auto w : x) nx.pb(w);
for (int i = 0; i < y.size(); i++) {
if (y[i] < nx[i]) r--;
if (y[i] > nx[i]) r++;
}
cout << r;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |