結果

問題 No.370 道路の掃除
ユーザー bluemeganebluemegane
提出日時 2018-10-25 20:02:24
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,070 bytes
コンパイル時間 852 ms
コンパイル使用メモリ 104,320 KB
実行使用メモリ 18,432 KB
最終ジャッジ日時 2024-04-29 21:39:41
合計ジャッジ時間 2,798 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
17,920 KB
testcase_01 AC 27 ms
17,920 KB
testcase_02 WA -
testcase_03 AC 26 ms
17,920 KB
testcase_04 WA -
testcase_05 AC 27 ms
17,920 KB
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 26 ms
18,048 KB
testcase_10 AC 26 ms
17,920 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 26 ms
17,792 KB
testcase_18 AC 26 ms
18,048 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 25 ms
17,792 KB
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 26 ms
18,048 KB
testcase_33 AC 26 ms
18,048 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var a = new int[m];
        for (int i = 0; i < m; i++) a[i] =  int.Parse(Console.ReadLine().Trim());
        Array.Sort(a);
        var L = getAns(a, n);
        var ans = getAns2(a, L, n);
        Console.WriteLine(ans);

    }
    public static int getAns2 (int[] a, int L , int n)
    {
        var r = L + n - 1;
        var ans1 = a[r] - a[L];
        if ((a[r] > 0 && a[L] >= 0)  | (a[r] < 0 && a[L] < 0) )     return  Max(Abs(a[L]), Abs(a[r]));
        else return ans1 + Min(Abs(a[L]), Abs(a[r]));
    }
    public static int getAns (int[] a , int n)
    {
        var m = a.Length;
        var minL = int.MaxValue;
        var mini = 0;
        for (int i = 0; i < m -n+1; i++)
        {
            var w = a[i + n - 1] - a[i];
            if (w < minL) { minL = w;  mini = i; }
        }
        return mini;
    }
}

0