My issue
include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
int D,d,p,q;
cin>>D>>d>>p>>q;
long long a[D]={0};
for(int i=0;i<D;i++){
if(i%d==0&&i!=0) {
a[i]=p+q;
p=p+q;}
else a[i]=p;
}
long long k=accumulate(a,a+D,0);
cout<<k<<endl;
}
return 0;
}
what is the issue in this code?
My code
#include <bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int D,d,p,q;
cin>>D>>d>>p>>q;
long long a[D]={0};
for(int i=0;i<D;i++){
if(i%d==0&&i!=0) {
a[i]=p+q;
p=p+q;}
else a[i]=p;
}
long long k=accumulate(a,a+D,0);
cout<<k<<endl;
}
return 0;
}
Problem Link: Bella ciao Practice Coding Problem - CodeChef