Average Number
Chef had a sequence of positive integers with length . He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by ), but then, his little brother deleted elements from it. All deleted elements had the same value.
Chef still knows the remaining elements — a sequence . Help him with restoring the original sequence by finding the value of the deleted elements or deciding that there is some mistake and the described scenario is impossible.
Note that the if it is possible for the deleted elements to have the same value, then it can be proven that it is unique. Also note that this value must be a positive integer.
Input
- The first line of the input contains a single integer denoting the number of test cases. The description of test cases follows.
- The first line of each test case contains three space-separated integers , and .
- The second line contains space-separated integers .
Output
For each test case, print a single line containing one integer — the value of the deleted elements, or if there is a mistake.
Constraints
- for each valid
Subtasks
Subtask #1 (100 points): original constraints
Example Input
3
3 3 4
2 7 3
3 1 4
7 6 5
3 3 4
2 8 3
Example Output
4
-1
-1
SOLUTION USING C LANGUAGE:-
#include <stdio.h>
int main(void) {
int T,i;
int N,K,V,A[1000];
scanf("%d\n",&T);
while(T--)
{
int s=0,r,u;
scanf("%d %d %d\n",&N,&K,&V);
for(i=0;i<N;i++)
{
scanf("%d ",&A[i]);
s=s+A[i];
}
u=((N+K)*V)-s;
r=u/K;
if(r>0 && (u%K==0))
printf("%d\n",r);
else
printf("-1\n");
}
// your code goes here
return 0;
}
No comments:
Post a Comment