結果

問題 No.54 Happy Hallowe'en
ユーザー 14番14番
提出日時 2016-06-13 05:04:44
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 2,947 bytes
コンパイル時間 1,033 ms
コンパイル使用メモリ 112,472 KB
実行使用メモリ 36,316 KB
最終ジャッジ日時 2024-04-17 19:01:08
合計ジャッジ時間 2,397 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 29 ms
19,200 KB
testcase_11 AC 29 ms
19,200 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 AC 29 ms
18,816 KB
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Collections.Generic;
using System.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int ieCount = int.Parse(Reader.ReadLine());
        List<Ie> tempList = new List<Ie>();
        int okashiTotal = 0;
        for(int i=0; i<ieCount; i++) {
            Ie ins = new Ie(i, Reader.ReadLine());
            tempList.Add(ins);
            okashiTotal+=ins.Okashi;
        }
        this.dic = new int[ieCount, okashiTotal+1];

        tempList.Sort((a,b)=>{
            if(a.Okashi + a.Sikii < b.Okashi + b.Sikii) {
                return -1;
            } else if(a.Okashi + a.Sikii > b.Okashi + b.Sikii) {
                return 1;
            } else if(a.Sikii < b.Sikii) {
                return -1;
            } else if(a.Sikii > b.Sikii) {
                return 1;
            }
            return 0;
        });
        this.IeList = tempList.ToArray();
        int ans = this.GetAns(0,0);
        Console.WriteLine(ans);
    }
    private int[,] dic;

    private int GetAns(int idx, int hasOkashi) {
        if(this.dic[idx, hasOkashi] > 0) {
            return this.dic[idx,hasOkashi];
        }

        int ans = 0;
        if(idx >= this.IeList.Length) {
            return ans;
        }

        if(idx == this.IeList.Length - 1) {
            if(IeList[idx].Sikii > hasOkashi) {
                ans = IeList[idx].Okashi;
            } else
            {
                ans = 0;
            }
        } else
        {
            for(int i=idx; i<this.IeList.Length; i++) {
                if(this.IeList[i].Sikii <= hasOkashi) {
                    continue;
                }
                int ret = this.GetAns(i+1, hasOkashi + this.IeList[i].Okashi) + this.IeList[i].Okashi;
                ans = Math.Max(ans, ret);
            }
        }
        dic[idx, hasOkashi] = ans;
        return ans;
    }


    private Ie[] IeList;

    public class Ie {
        public int Index;
        public int Okashi;
        public int Sikii;

        public Ie(int idx, string init) {
            int[] inpt = init.Split(' ').Select(a=>int.Parse(a)).ToArray();
            this.Index = idx;
            this.Okashi = inpt[0];
            this.Sikii = inpt[1];
        }
    }

    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


2
1 3
100 2



";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0