Average Number ||codechef||beginner solution ||programming info

Average Number

Chef had a sequence of positive integers with length N+K. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by V), but then, his little brother deleted K elements from it. All deleted elements had the same value.

Chef still knows the remaining N elements — a sequence A1,A2,,AN. 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 T denoting the number of test cases. The description of T test cases follows.
  • The first line of each test case contains three space-separated integers NK and V.
  • The second line contains N space-separated integers A1,A2,,AN.

Output

For each test case, print a single line containing one integer — the value of the deleted elements, or 1 if there is a mistake.

Constraints

  • 1T100
  • 1N,K100
  • 1V105
  • 1Ai105 for each valid i

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; }
Share:

No comments:

Post a Comment

Translate

Recommended platforms

  1. codechef
  2. hackerrank
  3. codeforces
  4. leetcode
  5. hackerearth

Popular Posts

programming_info. Powered by Blogger.

Blog Archive

Recent Posts

other platforms

  • geeks for geeks
  • w3schools
  • codepen
  • skillshare
  • udemy

Pages

reader support Support