結果

問題 No.156 キャンディー・ボックス
ユーザー Maeda
提出日時 2025-03-31 17:12:33
言語 C#
(.NET 8.0.404)
結果
AC  
実行時間 53 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 8,027 ms
コンパイル使用メモリ 169,728 KB
実行使用メモリ 186,244 KB
最終ジャッジ日時 2025-03-31 17:12:45
合計ジャッジ時間 11,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (115 ミリ秒)。
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

    class Program
    {
        static void Main(string[] args)
        {
            string[] numList = Console.ReadLine().Split(' ');
            int wantCandy = int.Parse(numList[1]);
            string[] candyBox = Console.ReadLine().Split(' ');
            int[] candyList = new int[int.Parse(numList[0])];
            for(int i = 0; i < int.Parse(numList[0]); i++)
            {
                candyList[i] = int.Parse(candyBox[i]);
            }
            Array.Sort(candyList);
            int count = 0;
            while(wantCandy > 0 && count < int.Parse(numList[0]))
            {
                wantCandy -= candyList[count];
                if(wantCandy >= 0)
                {
                    count++;
                }
            }
            Console.WriteLine(count);
        }
    }
0