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;
#ifdef Nero
#include "Deb.h"
#else
#define debug(...)
#endif
const int md = (int) 1e9 + 7;
void add(int& x, int y) {
x += y;
if (x >= md) {
x -= md;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<int> b(n);
for (int i = 0; i < n; ++i) {
cin >> b[i];
}
int water = 0;
for (int mask = 0; mask < (1 << n); ++mask) {
vector<int> c(n);
for (int i = 0; i < n; ++i) {
c[i] = (mask >> i & 1 ? b[i] : a[i]);
}
vector<int> d(n);
for (int i = 0; i < n; ++i) {
int mxL = *max_element(c.begin(), c.begin() + i + 1);
int mxR = *max_element(c.begin() + i, c.end());
d[i] = min(mxL, mxR);
add(water, d[i] - c[i]);
}
}
cout << water << '\n';
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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |