A. Arithmetic Array # 726 Div.2


https://codeforces.com/contest/1516/problem/A
1秒、256 MBメモリ
input :
  • t (1≤t≤1000)
  • n (1≤n≤50)
  • a1,…,an (−10^4≤ai≤10^4)
  • output :
  • For each test case, output a single integer — the minimum number of non-negative integers you have to append to the array so that the arithmetic mean of the array will be exactly 1.
  • のテストエンクロージャには、1桁の整数値が出力されます.(追加する整数数を出力)
  • 条件:

  • An array b of length k is called good if its arithmetic mean is equal to 1
  • kの長さを持つbアレイを満たすには、計算値は1でなければなりません.

  • 計算値は四捨五入できません.ミスと同じです.

  • In an operation, you can append a non-negative integer to the end of the array

  • 実行時に、非負の値を配列に追加できます.
  • 配列内の要素を加算した値(compare)を配列の個数(n)で割った場合は1になります.
    この時は3つの状況があります.
    1.比較がnより大きい
    2.比較がnに等しい
    3.比較がnより小さい
    1の場合、数値に0を追加する必要があります.compareとnの違いで、0の個数を追加しなければなりません.
    出力がnより小さい場合は、対応する正の値を追加して答えを生成することができます.同じ場合、これ以上何も触る必要がないので、1を出力します.
    import sys
    
    t = int(sys.stdin.readline())
    for i in range(t):
        n = int(sys.stdin.readline())
        data = list(map(int, sys.stdin.readline().split()))
    
        compare = sum(data)
        if compare > n:
            print(compare - n)
        elif compare == n:
            print(0)
        else:
            print(1)