A Simple EquationProblem code: TECH08 |
Given N,A,B,C, find how many solutions exist to the equation:
a + b + c <= N,
such that 0 <= a <= A, 0 <= b <= B, 0 <= c <= C.
Input
The first line contains the number of test cases T. Each test case contains 4 integers, N,A,B,C. 0 <= N,A,B,C <= 2500
Output:
Output T lines, one for each test case.
Example
Sample Input : 2 4 3 2 1 1 1 1 1 Sample Output : 20 4
| Author: | technovanza10 |
| Date Added: | 17-01-2010 |
| Time Limit: | 2 sec |
| Source Limit: | 50000 Bytes |
| Languages: | C, C99 strict, CLOJ, CPP 4.0.0-8, CPP 4.3.2, F#, GO, JAVA, PERL6, PYTH 3.1.2, TEXT |
Comments

Fetching successful submissions

What contest is this. No
What contest is this. No notification . Is this some trial contest or some internal competition for a specific group?
Codechef holds regular
Codechef holds regular competitions at various universities, etc. Basically, if you don't hear about it, it's not for you :)
#include <iostream.h>#include
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int x;
cin>>x;
for(int i=0;i<x;i++)
{
int N,A,B,C,count=0;
cin>>N>>A>>B>>c;
int a,b,c;
for(a=0,b=0,c=0;((a+b+c)<N)&&(a<A);a++)
{
++count;
}
for(a=0,b=0,c=0;((a+b+c)<N)&&(b<B);b++)
{
++count;
}
for(a=0,b=0,c=0;((a+b+c)<N)&&(c<C);c++)
{
++count;
}
cout<<count<<"n";
}