結果

問題 No.21 平均の差
ユーザー funakoshifunakoshi
提出日時 2019-06-20 14:51:36
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 55 ms / 5,000 ms
コード長 1,675 bytes
コンパイル時間 1,979 ms
コンパイル使用メモリ 106,588 KB
実行使用メモリ 22,748 KB
最終ジャッジ日時 2023-08-22 15:55:11
合計ジャッジ時間 3,260 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
20,820 KB
testcase_01 AC 55 ms
22,680 KB
testcase_02 AC 55 ms
20,688 KB
testcase_03 AC 55 ms
22,716 KB
testcase_04 AC 55 ms
22,640 KB
testcase_05 AC 55 ms
22,684 KB
testcase_06 AC 55 ms
20,796 KB
testcase_07 AC 54 ms
22,748 KB
testcase_08 AC 54 ms
20,712 KB
testcase_09 AC 54 ms
20,628 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace yukicoderTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string n = Console.ReadLine();
            string k = Console.ReadLine();
            int num = int.Parse(n);
            int group = int.Parse(k);
            int[] ary = new int[num];
            for (int i = 0; i < num; i++)
            {
                var line = Console.ReadLine();
                ary[i] = int.Parse(line);
            }

            for (int i = 0; i < ary.Length; i++)
            {

                for (int j = i + 1; j < ary.Length; j++)
                {
                    if (ary[i] < ary[j])
                    {
                        int temp = ary[i];
                        ary[i] = ary[j];
                        ary[j] = temp;
                    }


                }
                //Console.Write(ary[i] + " ");
            }
            int avg = 0;
            int cnt = 0;
            if(group%2==0)
            {
                Console.WriteLine(ary[0] - ary[ary.Length - 1]);
            }
            else
            {
                for(int i = ary.Length-1;group<i;i--)
                {
                    avg = avg + ary[i];
                    cnt++;
                }
                if (cnt != 0)
                {
                    avg = avg / cnt;
                    Console.WriteLine(ary[0] - avg);
                }
                else
                {
                    Console.WriteLine(ary[0] - ary[ary.Length - 1]);
                }
            }
        }
    }
}
0