結果

問題 No.1715 Dinner 2
ユーザー bluemeganebluemegane
提出日時 2021-10-23 11:14:59
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,740 bytes
コンパイル時間 1,935 ms
コンパイル使用メモリ 109,060 KB
実行使用メモリ 30,264 KB
最終ジャッジ日時 2023-10-25 07:03:13
合計ジャッジ時間 6,416 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
24,224 KB
testcase_01 AC 25 ms
24,200 KB
testcase_02 AC 25 ms
24,200 KB
testcase_03 AC 25 ms
24,196 KB
testcase_04 AC 25 ms
24,196 KB
testcase_05 AC 25 ms
24,196 KB
testcase_06 AC 25 ms
24,196 KB
testcase_07 AC 25 ms
24,200 KB
testcase_08 AC 25 ms
24,196 KB
testcase_09 AC 25 ms
24,196 KB
testcase_10 AC 25 ms
24,196 KB
testcase_11 TLE -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var d = int.Parse(line[1]);
        var p = new int[n ];
        var q = new int[n ];
        for (int i = 0; i < n; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            p[i] = int.Parse(line[0]);
            q[i] = int.Parse(line[1]);
        }
        getAns(n, d, p, q);

    }
    static void getAns (int n, int d, int [] p, int[] q)
    {
        var ok = -100000000;
        var ng = 0;
        while (ng -ok > 1)
        {
            var mid = ok + (ng - ok) / 2;
            if (check(n, d, p, q, mid)) ok = mid;
            else ng = mid;
        }
        Console.WriteLine(ok);
    }

    static bool check (int n, int d, int[]p, int[]q ,  int t)
    {
        var dp = new int[d + 1, n];
        for (int i = 0; i < d + 1; i++)
            for (int j = 0; j < n; j++) dp[i, j] = int.MinValue;
        for (int i = 0; i < n; i++)
            if (-p[i] >= t) dp[1, i] = -p[i] + q[i];
        for (int i = 2; i <= d; i++)
        {
            for (int j = 0; j < n; j++)
            {
                for (int k = 0; k < n; k++)
                {
                    if (j == k) continue;
                    if (dp[i - 1, j] == int.MinValue) continue;
                    var temp = dp[i - 1, j] - p[k];
                    if (temp < t) continue;
                    temp += q[k];
                    dp[i, k] = Max(dp[i, k], temp);
                }
            }
        }
        for (int i = 0; i < n; i++)
            if (dp[d,i] != int.MinValue) { return true; }
        return false;
    }
}
0