結果
| 問題 | 
                            No.370 道路の掃除
                             | 
                    
| コンテスト | |
| ユーザー | 
                             mban
                         | 
                    
| 提出日時 | 2017-01-10 03:55:58 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 30 ms / 2,000 ms | 
| コード長 | 2,224 bytes | 
| コンパイル時間 | 1,059 ms | 
| コンパイル使用メモリ | 112,448 KB | 
| 実行使用メモリ | 26,516 KB | 
| 最終ジャッジ日時 | 2024-12-18 00:21:23 | 
| 合計ジャッジ時間 | 3,033 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 34 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;
class Magatro
{
    static Scanner sc = new Scanner();
    static int N, M;
    static List<int> L=new List<int>(), R=new List<int>();
    static void Main()
    {
        N = sc.NextInt();
        M = sc.NextInt();
        for(int i = 0; i < M; i++)
        {
            int next = sc.NextInt();
            if (next >= 0)
            {
                R.Add(next);
            }
            else
            {
                L.Add(next);
            }
        }
        R.Sort();
        L.Sort((a, b) => a.CompareTo(b) * -1);
        int ans = int.MaxValue;
        for(int r = 0; r <= N; r++)
        {
            int l = N - r;
            if (R.Count >= r && L.Count >= l)
            {
                if (r == 0)
                {
                    ans = Math.Min(ans, Math.Abs(L[l - 1]));
                }
                else if (l == 0)
                {
                    ans = Math.Min(ans, R[r - 1]);
                }
                else
                {
                    int min = Math.Min(R[r - 1], Math.Abs(L[l - 1]));
                    int max = Math.Max(R[r - 1], Math.Abs(L[l - 1]));
                    ans = Math.Min(ans, min * 2 + max);
                }
            }
        }
        Console.WriteLine(ans);
    }
}
public class Scanner
{
    public string[] S;
    private int Index;
    private char Separator;
    public Scanner(char separator=' ')
    {
        Index = 0;
        Separator = separator;
    }
    public string Next()
    {
        string result;
        if (S == null || Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    private string[] Line()
    {
        return Console.ReadLine().Split(Separator);
    } 
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
            
            
            
        
            
mban