Help me in solving MAXSCORE7 problem

My issue

can someone let me know on which test case this is failing?

My code

#include <iostream>
#include <vector>
#include <cmath>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--){
	    int n;
	    cin>>n;
	    vector<int> v;
	    for(int i=0;i<n;i++){
	       int a;
	        cin>>a;
	        v.push_back(a);
	    }
	    int score=0;
	    int p=n/2;
	    int i=1;
	    while(p--){
	        
	        if(p>1){
	         score+=abs(v[i]-v[i+1]);
	        }
	         else{
	            score+=abs(v[0]-v[i]) ;
	         }
	         i=i+2;
	    }
	    
	    cout<<score<<endl;
	    
	}
	
}

Problem Link: Maximum Score Practice Coding Problem - CodeChef

@itz_keshav
refer my c++ code for better understanding of the logic

#include <iostream>
using namespace std;

int main() {
	// your code goes here
	int t;
	cin>>t;
	while(t--)
	{
	    int n;
	    cin>>n;
	    int a[n];
	    int cnt=0;
	    for(int i=0;i<n;i++)
	    {
	        cin>>a[i];
	        if(a[i]==1)
	        cnt++;
	    }
	    cout<<min(cnt,(n-cnt))<<endl;
	}
	return 0;
}