結果

問題 No.54 Happy Hallowe'en
ユーザー nanophoto12
提出日時 2014-11-01 15:20:03
言語 C#(csc)
(csc 3.9.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,627 bytes
コンパイル時間 3,296 ms
コンパイル使用メモリ 107,648 KB
実行使用メモリ 218,368 KB
最終ジャッジ日時 2024-12-30 16:01:53
合計ジャッジ時間 6,399 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18 WA * 1
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 (j + value < size + 1)
                {
                    if (dp[j] != int.MinValue)
                    {
                        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