結果

問題 No.54 Happy Hallowe'en
ユーザー nanophoto12nanophoto12
提出日時 2014-11-01 15:17:26
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 2,318 ms
コンパイル使用メモリ 103,712 KB
実行使用メモリ 222,528 KB
最終ジャッジ日時 2023-08-29 00:07:48
合計ジャッジ時間 7,055 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
21,652 KB
testcase_01 AC 65 ms
21,792 KB
testcase_02 AC 60 ms
19,564 KB
testcase_03 AC 59 ms
23,656 KB
testcase_04 AC 141 ms
45,712 KB
testcase_05 AC 195 ms
69,816 KB
testcase_06 AC 265 ms
94,052 KB
testcase_07 AC 374 ms
131,808 KB
testcase_08 AC 505 ms
172,292 KB
testcase_09 AC 626 ms
222,528 KB
testcase_10 AC 59 ms
21,664 KB
testcase_11 AC 62 ms
23,640 KB
testcase_12 AC 323 ms
25,756 KB
testcase_13 AC 617 ms
218,600 KB
testcase_14 RE -
testcase_15 AC 58 ms
23,660 KB
testcase_16 AC 62 ms
23,672 KB
testcase_17 WA -
testcase_18 AC 60 ms
21,668 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Globalization;
using System.Linq;

class Program
{
    public static void Main(string[] args)
    {
        int n = int.Parse(Console.ReadLine());
        Tuple<int,int>[] valueAndThresholds = new Tuple<int, int>[n];
        for (int i = 0; i < n; i++)
        {
            var line = Console.ReadLine().Split(' ').Select(element => int.Parse(element)).ToArray();
            valueAndThresholds[i] = new Tuple<int, int>(line[0], line[1]);
        }

        Array.Sort(valueAndThresholds, (tuple, tuple1) => (tuple.Item2 + tuple.Item1).CompareTo(tuple1.Item2 + tuple1.Item1));
        var size = valueAndThresholds.Sum(element => element.Item1);

        var dp = new int[size + 1];
        for (int i = 0; i < dp.Length; i++)
        {
            dp[i] = int.MinValue;
        }
        dp[0] = 0;
        for (int index = 0; index < n; index++)
        {
            var current = valueAndThresholds[index];
            var threshold = current.Item2;
            var value = current.Item1;
            for (int j = 0; j < threshold; j++)
            {
                if (dp[j] != int.MinValue)
                {
                    if (j + value < size + 1)
                    {
                        dp[j + value] = Math.Max(dp[j + value], dp[j] + value);
                    }                    
                }
            }
        }
        int max = 0;
        for (int i = 0; i < dp.Length; i++)
        {
            max = Math.Max(max, dp[i]);
        }
        Console.WriteLine(max.ToString(CultureInfo.InvariantCulture));
    }
}
0