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 ff first
#define ss second
#define pb push_back
#define int long long
const int N=3e5+5;
int h[N];
int w[N];
int ps[N];
int mod=1e9+7;
int modd(int n){
return (n%mod+mod)%mod;
}
int calc(int a, int b){
int f=modd(modd(a*(a+1))*500000004);
int s=modd(modd(b*(b+1))*500000004);
return (f*s)%mod;
}
signed main(){
int n;
cin>>n;
for(int i=1;i<=n;i++){
cin>>h[i];
}
for(int i=1;i<=n;i++){
cin>>w[i];
}
int ans=0;
ps[n+1]=0;
for(int i=n;i>=1;i--){
ps[i]=ps[i+1]+w[i];
// cout<<ps[i]<<" "<<h[i]<<" ";
// cout<<calc(h[i],ps[i])<<" "<<calc(h[i-1],ps[i])<<endl;
ans+=calc(h[i],ps[i])-calc(h[i-1],ps[i]);
//cout<<ans<<endl;
ans=modd(ans);
}
cout<<ans;
}
# | 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... |