結果

問題 No.156 キャンディー・ボックス
ユーザー 明智重蔵
提出日時 2015-08-28 21:22:31
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 1,611 bytes
コンパイル時間 2,103 ms
コンパイル使用メモリ 108,160 KB
実行使用メモリ 19,456 KB
最終ジャッジ日時 2024-07-05 15:42:26
合計ジャッジ時間 4,014 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

class Program
{
    static string InputPattern = "Input5";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("3 2");
            WillReturn.Add("1 2 3");
            //1
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("3 2");
            WillReturn.Add("1 1 3");
            //2
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("4 10");
            WillReturn.Add("3 2 4 1");
            //4
        }
        else if (InputPattern == "Input4") {
            WillReturn.Add("6 257109");
            WillReturn.Add("53771 46578 31908 80435 62678 4327");
            //5
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int M = InputList[0].Split(' ').Select(X => int.Parse(X)).Last();
        int[] CArr = InputList[1].Split(' ').Select(X => int.Parse(X)).ToArray();

        Array.Sort(CArr);

        int TatalCnt = 0;
        for (int I = 0; I <= CArr.GetUpperBound(0); I++) {
            TatalCnt += CArr[I];

            if (TatalCnt > M) {
                Console.WriteLine(I);
                break;
            }
            else if (TatalCnt == M) {
                Console.WriteLine(I + 1);
                break;
            }
        }
    }
}
0