I used STL inbuilt accumulate() function to get the solution of this problem and it gives me wrong answer but when I used the same logic but removed accummulate() and calculated the sum manually, my solution got passed. What’s wrong with accumulate() function?
Click here to go to the problem and here for the link to my solution.
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
unsigned long long a[n],b[n];
for(int i=0;i<n;i++){
cin>>a[i];
b[i] = a[i] - 1;
}
unsigned long long k = accumulate(b,b+n,1);
cout<<k<<endl;
}
return 0;
}