Deep_Dev

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXGEbd6cjMDFAUo 

 

SW Expert Academy

SW ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์—ญ๋Ÿ‰ ๊ฐ•ํ™”์— ๋„์›€์ด ๋˜๋Š” ๋‹ค์–‘ํ•œ ํ•™์Šต ์ปจํ…์ธ ๋ฅผ ํ™•์ธํ•˜์„ธ์š”!

swexpertacademy.com

 


์ˆซ์ž 1๋‹น ์›€์ง์ž„ 1ํšŒ์ด๊ณ ..

๋‚ด๊ฐ€ ํ‘ผ ๋ฐฉ์‹์€

๊ฑด์ดˆ๋”๋ฏธ์˜ ์ด ํ•ฉ์˜ ํ‰๊ท ์„ ๋งŒ๋“œ๋Š”๊ฑฐ๋‹ˆ๊นŒ, ํ‰๊ท ์„ ๊ตฌํ•œ๋‹ค์Œ์—

ํ‰๊ท ๋ณด๋‹ค ์ž‘์€ ์ˆซ์ž๋“ค์ด ํ‰๊ท ๊นŒ์ง€ ์ฐจ์ด๋ฅผ ๋‹ค ๋”ํ•˜๋ฉด ๊ทธ๊ฒŒ ์›€์ง์ž„ ํšŸ์ˆ˜์ด๋‹ค.

 

๊ณ ๋ ค๋ฅผ ์•ˆํ•ด๋„ ๋˜๋Š” ์š”์†Œ๊ฐ€ ์žˆ๋Š”๋ฐ, ์ด๋ฏธ ํ‰๊ท ๋ณด๋‹ค ํฐ ๊ฒฝ์šฐ๋Š” ์นด์šดํŒ…ํ•˜์ง€์•Š์•„๋„ ๋œ๋‹ค.

 

import java.util.Scanner;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int n=kb.nextInt();
            int[] arr=new int[n];
            int sum=0;
            for(int i=0; i<n; i++) {
                arr[i] = kb.nextInt();
                sum+=arr[i];
            }
            int avg=sum/n;
            int cnt=0;
            for(int i=0; i<n; i++){
                if(arr[i]<avg)
                    cnt+=avg-arr[i];
            }
            System.out.println("#"+t+" "+cnt);
        }
    }
}