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>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const ll md = 1e9+7;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> A(n), B(n);
for(ll &x: A) cin >> x;
for(ll &x: B) cin >> x;
ll ans = 0;
for(int k = 0; k < (1<<n); k++){
vector<ll> C(n);
ll cur = 0;
for(int i = 0; i < n; i++){
if(k&(1<<i)) C[i] = B[i];
else C[i] = A[i];
cur-=C[i], cur%=md;
}
vector<ll> suff(n, 0);
for(int i = n-1; i >= 0; i--){
if(i+1 < n) suff[i] = suff[i+1];
suff[i] = max(suff[i], C[i]);
}
ll mx = 0;
for(int i = 0; i < n; i++){
mx = max(mx, C[i]);
cur+=min(mx, suff[i]), cur%=md;
}
if(cur < 0) cur+=md;
ans+=cur;
ans%=md;
}
cout << ans << "\n";
}
# | 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... |