https://www.codechef.com/LTIME71B/problems/FASTFOOD

Can anyone tell on which test case it is getting wrong!!!

#include
using namespace std;

int main() {
// your code goes here
int t;
cin>>t;
for(int s=1;s<=t;s++)
{
int n;
cin>>n;
int value1[n],value2[n];
for(int i=0;i<n;i++)
{
cin>>value1[i];
}
for(int i=0;i<n;i++)
{
cin>>value2[i];
}
// int pre=0;
bool one=false;
if(n==1)
{
if(value1[0]>value2[0])
{
cout<<value1[0]<<endl;
}
else
{
cout<<value2[0];
}
one =true;
}
int full_sum2=0,full_sum1=0;
for(int i=0;i<n;i++)
{
full_sum2=full_sum2+value2[i];
}
for(int i=0;i<n;i++)
{
full_sum1=full_sum1+value1[i];
}
int ans=0,final_ans=0;
bool second=false;
int check1=full_sum1,check2=full_sum2;
for(int i=0;i<n;i++)
{
ans=ans+value1[i];
check1=check1-value1[i];
check2=check2-value2[i];
if(check2>check1)
{
final_ans=check2+ans;
second=true;
//cout<<i<<endl;
break;
}
}
if(one)
{
break;
}
if(second)
{

        if(full_sum2<final_ans)
        {
            cout<<final_ans<<endl;
        }
        else
        {
            cout<<full_sum2<<endl;
            //cout<<"wrong";
        }
    }
    else
    {
       // cout<<"ans"<<endl;
        cout<<ans<<endl;
    }
    
    
}
return 0;

}

It’s better if you post a link of your solution instead of copy pasting it directly, its hard to read. and tell your approach also then only i will be able to see whats happening in code.

https://www.codechef.com/viewsolution/25394925

here basically i tried to take sum of running index and all the forward index and compare it on every moment.
Hope you understood.

I dont think that would work, i’ve solved this question. You need to maintain two arrays, at each index the first array should contain the cumulative sum of first city and second array at that index would contain the future cumulative sum in other city if he moved at that day. NOW you should compare it at every index, and take the max.

Here’s My AC Solution , it’s very neat so you can understand :slight_smile:
https://www.codechef.com/viewsolution/24947433