#include
#include <math.h>
using namespace std;
int main() {
int long long n;
cin >> n;
int long long a[n]={0};
for(int long long i=0;i<n;i++){
cin >> a[i];
}
int long long q;
cin >> q;
int next[n]={0};
int long long sec = n-1;
while(q!=0){
int x;
cin >> x;
if(x>0){
int long long j=x;
while(j!=0){
for(int long long i=0; i<n; i++){
next[i]=a[i]+a[sec];
//cout << next[i] << " ";
sec = i;
}
for(int long long i=0;i<n;i++){
a[i]=next[i];
}
j–;
}
}
//cout << endl;
if(x==0){
for(int long long i=0;i<n;i++){
next[i]=a[i]+a[i];
//cout << next[i] << " ";
}
}
for(int long long i=0;i<n;i++){
a[i]=next[i];
}
q–;
}
int long long sum = 0;
for(int long long i=0;i<n;i++){
sum+=a[i];
}
//cout << sum;
int long long ans;
int long long base = pow(10,9)+7;
ans = sum % base ;
cout << ans;
return 0;
}
Calculate the sum: last test case error. Problem in code?
kindly share the link of code
so that i can run and check what’s wrong
i think you have misinterpreted the question
if array is of size 5 and this is the array {1 2 3 4 5 } and x=2 then new array will be
{1+4,2+5,3+1,4+2,5+3}
you can refer this simple code
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.