結果

問題 No.609 Noelちゃんと星々
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-09 00:03:55
言語 Java21
(openjdk 21)
結果
AC  
実行時間 265 ms / 2,000 ms
コード長 1,710 bytes
コンパイル時間 4,103 ms
コンパイル使用メモリ 74,112 KB
実行使用メモリ 58,748 KB
最終ジャッジ日時 2023-08-19 23:10:27
合計ジャッジ時間 10,856 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
58,648 KB
testcase_01 AC 178 ms
56,432 KB
testcase_02 AC 166 ms
56,116 KB
testcase_03 AC 190 ms
55,784 KB
testcase_04 AC 147 ms
55,300 KB
testcase_05 AC 258 ms
58,508 KB
testcase_06 AC 227 ms
58,356 KB
testcase_07 AC 224 ms
56,204 KB
testcase_08 AC 130 ms
53,240 KB
testcase_09 AC 177 ms
55,844 KB
testcase_10 AC 197 ms
56,536 KB
testcase_11 AC 224 ms
56,492 KB
testcase_12 AC 243 ms
56,620 KB
testcase_13 AC 134 ms
53,624 KB
testcase_14 AC 101 ms
52,852 KB
testcase_15 AC 231 ms
58,500 KB
testcase_16 AC 264 ms
58,748 KB
testcase_17 AC 254 ms
58,472 KB
testcase_18 AC 167 ms
55,108 KB
testcase_19 AC 261 ms
58,544 KB
testcase_20 AC 259 ms
58,708 KB
testcase_21 AC 265 ms
58,440 KB
testcase_22 AC 261 ms
58,624 KB
testcase_23 AC 260 ms
58,356 KB
testcase_24 AC 247 ms
58,628 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;


class Main {
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        long[]y=new long[n];
        for(int i=0;i<n;++i)y[i]=sc.nextLong();
        Arrays.sort(y);
        long m=y[n/2];
        long t=0;
        for(int i=0;i<n;++i)t+=Math.abs(y[i]-m);
        out.println(t);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}
0