can someone tell me what's wrong with this code. Problem Code:PLPROCESS

Problem Code:PLPROCESS
link;-CodeChef: Practical coding for everyone

Only One test case fail

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

int main() {

ios_base::sync_with_stdio(false);cin.tie(NULL);


int TC;
cin>>TC;
while(TC--)
{
    int n;int ans=0;int sum=0;int sum2=0;
    cin>>n;
    
    int v1[n]; int v2[n];
    
    for(int i=0;i<n;i++)
    {
        cin>>v1[i];
        sum+=v1[i];
    }
   ans=sum;
    
    for(int i=0;i<n;i++){
        
        sum2+=v1[i];
        
        
    int temp=max(sum2,sum-sum2);
    v2[i]=temp;
    
    }
    sort(v2,v2+n);
    
   cout<<v2[0]<<endl;
 }

// your code goes here
return 0;

}

Your code is failing for the cases when the input becomes too large that it can’t be stored in the int data type.
Make sure you use, long long int everywhere.

1 Like

Thanks now its working …