Grtting TLE For EQUATION

#include <stdio.h>
#include

int main()
{

int t;
scanf("%d",&t);

while(t–)
{
long long int N,A,B,C,i,j;
scanf("%lld %lld %lld %lld",&N,&A,&B,&C);
long long int ans=0;
for(i=0;i<=A;i++)
for(j=0;j<=B;j++)
if(i+j<=N)
ans+=std::min(N+1-i-j,C+1);

printf("%lld\n",ans);
}
return 0;
}

This approach will surely lead to TLE as the complexity is very large

You have to go for the concept of INCLUSION-EXCLUSION

Read this thread for above mentioned approach which will help to get AC for this problem and will clear all your doubts,

http://discuss.codechef.com/questions/53205/need-editorial-for-problem-a-simple-equationequation-easy

:slight_smile: