結果

問題 No.1522 Unfairness
ユーザー 👑 kakel-sankakel-san
提出日時 2024-06-02 20:57:44
言語 C#
(.NET 8.0.203)
結果
AC  
実行時間 178 ms / 2,000 ms
コード長 1,338 bytes
コンパイル時間 19,351 ms
コンパイル使用メモリ 166,516 KB
実行使用メモリ 185,832 KB
最終ジャッジ日時 2024-06-02 20:58:08
合計ジャッジ時間 13,619 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
30,848 KB
testcase_01 AC 64 ms
30,848 KB
testcase_02 AC 60 ms
30,848 KB
testcase_03 AC 91 ms
50,432 KB
testcase_04 AC 70 ms
36,736 KB
testcase_05 AC 65 ms
33,664 KB
testcase_06 AC 64 ms
32,128 KB
testcase_07 AC 104 ms
59,520 KB
testcase_08 AC 107 ms
59,520 KB
testcase_09 AC 66 ms
32,768 KB
testcase_10 AC 76 ms
39,772 KB
testcase_11 AC 69 ms
35,548 KB
testcase_12 AC 81 ms
44,032 KB
testcase_13 AC 120 ms
71,040 KB
testcase_14 AC 73 ms
35,200 KB
testcase_15 AC 169 ms
103,424 KB
testcase_16 AC 178 ms
103,424 KB
testcase_17 AC 170 ms
103,552 KB
testcase_18 AC 166 ms
103,296 KB
testcase_19 AC 167 ms
103,296 KB
testcase_20 AC 177 ms
103,296 KB
testcase_21 AC 64 ms
30,940 KB
testcase_22 AC 62 ms
30,848 KB
testcase_23 AC 59 ms
30,720 KB
testcase_24 AC 63 ms
31,732 KB
testcase_25 AC 60 ms
30,720 KB
testcase_26 AC 64 ms
32,128 KB
testcase_27 AC 61 ms
30,720 KB
testcase_28 AC 61 ms
30,696 KB
testcase_29 AC 63 ms
185,832 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
  復元対象のプロジェクトを決定しています...
  /home/judge/data/code/main.csproj を復元しました (96 ms)。
MSBuild のバージョン 17.9.6+a4ecab324 (.NET)
  main -> /home/judge/data/code/bin/Release/net8.0/main.dll
  main -> /home/judge/data/code/bin/Release/net8.0/publish/

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    public static void Main()
    {
        Solve();
    }
    static void Solve()
    {
        var c = NList;
        var (n, m) = (c[0], c[1]);
        var a = NList;
        Array.Sort(a, (l, r) => r.CompareTo(l));
        var INF = long.MinValue;
        var dp = new long[n][];
        for (var i = 0; i < n; ++i) dp[i] = Enumerable.Repeat(INF, m + 1).ToArray();
        for (var i = 0; i < n; ++i)
        {
            if (i > 0)
            {
                for (var j = 0; j <= m; ++j) dp[i][j] = dp[i - 1][j];
            }
            if (i == 0) dp[i][0] = 0;
            else if (i == 1)
            {
                if (a[i - 1] - a[i] <= m) dp[i][a[i - 1] - a[i]] = a[i - 1];
            }
            else if (i > 1)
            {
                for (var j = 0; j <= m; ++j)
                {
                    if (j + a[i - 1] - a[i] > m) break;
                    dp[i][j + a[i - 1] - a[i]] = Math.Max(dp[i][j + a[i - 1] - a[i]], dp[i - 2][j] + a[i - 1]);
                }
            }
        }
        WriteLine(dp[^1].Max());
    }
}
0