Help me in solving PLPROCESS problem

My issue

error in test case 2

My code

#include <bits/stdc++.h>
using namespace std;

int main() {
int t,d;
cin>>t;
for(d=0;d<t;d++){
    long long b,x,c=100000000,n,asum=0,sum=0,y,z;
    cin>>n;
    long long a[n];
    for(b=0;b<n;b++){
       cin>>a[b];
       sum+=a[b];
    }
    y=sum;
    sort(a,a+n);
    
    for(b=n-1;b>=0;b--){
     sum=sum-a[b];
     asum=asum+a[b];
     x=abs(sum-asum);
     if(x<c){c=x;z=max(sum,asum);}
    }
    y=y-c;
    cout<<c+y/2<<endl;  
    
       }

}

Problem Link: Parallel Processing Practice Coding Problem

@aditya11011
here plzz refer the following code for better understanding

#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main() {
	// your code goes here //prefix sum...............!!
	ll int t;
	cin>>t;
	while(t--)
	{
	    ll int n;
	    cin>>n;
	    
	    ll int *a=new ll int[n];
	    for(ll int i=0;i<n;i++)
	    cin>>a[i];
	    
	 
	 for(ll int i=1;i<n;i++)
	 a[i]+=a[i-1];
	 
	 ll int mx=INT_MIN,mn=1e15;
	 for(ll int i=0;i<n;i++)
	 {
	     mx=max(a[i], a[n-1]-a[i]);
	     mn=min(mn, mx);
	 }
	   std::cout << mn << std::endl;
	}
	
	return 0;
}
1 Like

can you help me getting error in my approach