Help me in solving FINALSALE problem

My issue

i dont know which answer is wrong and which taste case failed .can you tell me test case across 2nd

My code

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

int main() {
	// your code goes here
     int t;
     cin>>t;
     while(t--){
         int n,maxi=0,sum=0;
         cin>>n;
         int arr[n],sales[n];
         
         for(int i=0;i<n;i++)
         cin>>arr[i];
         
         for(int i=0;i<n;i++){
             sum+=arr[i];
             sales[i]=sum+arr[i];
         }
         
         for(int i=0;i<n;i++){
             maxi=max(sales[i],maxi);
         }
         
         cout<<maxi<<endl;
     }
     return 0;
}

Problem Link: Sale Practice Coding Problem - CodeChef

Your logic is correct and efficent.

But you have to consider that you are summing several 10^9 numbers. Your “int” variables are overflowing. Get used to using long long.

That’s it.

1 Like

wtf was that…i use long long and all test case passed.
Thank you

1 Like