I got WA in this problem.... even after getting correct output in dry run. Please help

https://www.codechef.com/problems/SEAARASU

 #include <iostream>
   #include <algorithm>

    int main()
   {
     int t;
    std::cin >> t;
  while(t--)
  {
int n;
std::cin >> n;
int arr[n];
for(int i=0;i< n;++i)
{
    std::cin >> arr[i];
}

int j;
int i;
for(i=n-1,j=i-1;i>=0 && j>=0;--i,--j)
{
    arr[i] = arr[i] - arr[j];
}
    int sum = 0;
   for(int i=0 ;i<n;++i)
   {
       sum = sum + arr[i];
     }
    std::cout << sum << " ";
     std::cout << '\n';
    }

    return 0 ;
}
1 Like

You are just substracting a[i] by a[i-1], it will not yield you the answer,
Eg test case
1
3
2 6 4
Answer is 6
Yours is 4
P.S.: Just go through the editorial that how this question could be solved

1 Like

Thanks that worked !