Problem:-
You are given arrays and , each of the size . Each element of these arrays is either a positive integer or . The total number of that can appear over these arrays are and .
Now, you need to find the number of ways in which we can replace each with a non-negative integer, such that the sum of both of these arrays is equal.
Input format
- First line: An integer
- Second line: space-separated integers, where the of these denotes
- Third line: space-separated integers, where the of these denotes
Output format
If there exists a finite number , then print it. If the answer is not a finite integer, then print 'Infinite'.
Constraints
The may spread out among both arrays, and their quantity is between and (both inclusive)
Sample Input 2
4 1 2 -1 4 3 3 -1 1
Sample Output 2
Infinite
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation
We can replace the only by , so that the sum of both of these arrays become .
Code:-
#include<stdio.h>
int main()
{
long int n,i,flag1=0,flag2=0;
scanf("%ld",&n);
long long int element,sum1=0,sum2=0;
for(i=0;i<n;i++)
{
scanf("%lld",&element);
if(element==-1)
flag1++;
else
sum1=sum1+element;
}
for(i=0;i<n;i++)
{
scanf("%lld",&element);
if(element==-1)
flag2++;
else
sum2=sum2+element;
}
if(flag1==flag2 && flag1==1)
printf("Infinite");
else{
if(flag1>flag2)
{
if(sum1>sum2)
printf("0");
else{
if(flag1==1 && flag2==0)
printf("1");
else
printf("55");
}
}
else
{
if(sum1<sum2)
printf("0");
else{
if(flag2==1 && flag1==0)
printf("1");
else
printf("55");
}
}
}
return 0;
}
0 Comments