This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define sz(v) int(v.size())
#define ar array
typedef long long ll;
const int N = 50, MOD = 1e9+7;
void solve() {
int n; cin >> n;
vector<ll> a(n); for (auto& x : a) cin >> x;
vector<ll> b(n); for (auto& x : b) cin >> x;
// I want to be matched with things lower than me
ll happy = 0;
int p = n-1;
for (int i = n-1; i >= 0; i--) {
p = min(p, i-1);
while (b[i]) {
while (p >= 0 && a[p] == 0) p--;
if (p < 0) break;
ll cur = min(b[i], a[p]);
happy += cur;
b[i] -= cur;
a[p] -= cur;
}
}
ll sad = 0;
for (int i = 0; i < n; i++) {
ll cur = min(a[i], b[i]);
sad += b[i] - cur;
}
cout << happy - sad << '\n';
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int T = 1;
// cin >> T;
while (T--) solve();
}
# | 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... |