結果

問題 No.914 Omiyage
ユーザー tsushimatsushima
提出日時 2019-10-25 22:38:43
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,606 bytes
コンパイル時間 2,288 ms
コンパイル使用メモリ 68,388 KB
実行使用メモリ 23,988 KB
最終ジャッジ日時 2023-10-11 05:42:05
合計ジャッジ時間 4,733 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 64 ms
23,868 KB
testcase_03 WA -
testcase_04 AC 62 ms
19,792 KB
testcase_05 WA -
testcase_06 RE -
testcase_07 RE -
testcase_08 WA -
testcase_09 AC 61 ms
21,844 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 AC 61 ms
21,876 KB
testcase_19 AC 61 ms
21,756 KB
testcase_20 AC 61 ms
23,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static int N, M, K;
        static int[][] A;
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = l[0];
            M = l[1];
            K = l[2];
            A = new int[N][];

            for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var sumList = new List<int>();
            for (var i = 0; i < M; i++)
            {
                var sum = 0;
                for (var j = 0; j < N; j++)
                {
                    sum += A[j][i];
                }
                sumList.Add(sum);
            }

            var targetIndex = -1;
            for (var i = sumList.Count - 1; i >= 0; i--)
            {
                if (sumList[i] <= K) targetIndex = i;
            }

            if (targetIndex == -1)
            {
                Console.WriteLine(-1);
                return;
            }

            M = targetIndex;

            var ans = Dfs(0, 0);
            Console.WriteLine(ans == 0 ? -1 : K - ans);

        }

        static int Dfs(int n, int total)
        {
            if (n == N)
            {
                if (total <= K) return total;
                else return -1;
            }

            var max = 0;
            for (var i = M; i < M + 2; i++)
            {
                max = Math.Max(max, Dfs(n + 1, total + A[n][i]));
            }

            return max;
        }
    }
}
0