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 int long long
#define pii pair<int,int>
const int MAX_N = 1e5;
const int mod =1e9+7;
int h[MAX_N];
int w[MAX_N];
int nbp(int u){
return (u*(u+1LL)/2LL)%mod;
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
for(int i = 0; i<n; i++){
cin>>h[i];
}
for(int i = 0; i<n; i++){
cin>>w[i];
}
int res= 0;
for(int l = 0; l<n; l++){
int minh= h[l];
for(int r = l; r<n; r++){
minh= min(minh, h[r]);
if(r!=l){
res = (res+((nbp(minh) * w[l])%mod)*w[r])%mod;
}
else{
res=(res+ (nbp(minh) * nbp(w[l]))%mod)%mod;
}
}
}
cout<<res<<endl;
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |