結果

問題 No.5 数字のブロック
ユーザー SagToki
提出日時 2018-06-07 14:40:33
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 36 ms / 5,000 ms
コード長 1,544 bytes
コンパイル時間 760 ms
コンパイル使用メモリ 111,748 KB
実行使用メモリ 28,152 KB
最終ジャッジ日時 2024-11-18 12:27:17
合計ジャッジ時間 2,677 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 34
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 Yukicorder
{
    class Program
    {
        public static void Main(String[] args)
        {
            var L = Input(1, 10000);
            var N = Input(1, 10000);
            int[] W = InputArray(1, L);
            int Answer = Processing(L, N, W);
            Console.WriteLine(Answer);

        }

        public static int Input(int Min , int Max)
        {
            int Number = int.Parse(Console.ReadLine());
            try{
                if (Number < Min || Number > Max)
                {
                    Console.WriteLine(Min + "以上" + Max + "以下で入力してください");
                }
            }catch(Exception E){
                Console.WriteLine("想定外のエラーです");
            }
            return Number;
        }

        public static int[] InputArray(int Min, int Max)
        {
            int[] Numbers = Console.ReadLine().Split().Select(int.Parse).ToArray();
            Array.Sort(Numbers);
            return Numbers;
        }

        public static int Processing(int L , int N , int[] W)
        {
            int Sum = 0;
            int Count = 0;
            for(int i = 0; i < N; i++)
            {
                if(L >= Sum + W[i])
                {
                    Sum += W[i];
                    Count++;
                }else{
                    break;
                }
            }
            return Count;
        }

    }
}
0