結果

問題 No.54 Happy Hallowe'en
ユーザー 14番14番
提出日時 2016-06-13 05:00:40
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 3,094 bytes
コンパイル時間 966 ms
コンパイル使用メモリ 108,544 KB
実行使用メモリ 25,392 KB
最終ジャッジ日時 2024-04-17 19:01:03
合計ジャッジ時間 7,695 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

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

        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 Dictionary<int, Dictionary<int, int>> dic = new Dictionary<int, Dictionary<int, int>>();

    private int GetAns(int idx, int hasOkashi) {
        if(!this.dic.ContainsKey(idx)) {
            this.dic.Add(idx, new Dictionary<int, int>());
        }
        if(this.dic[idx].ContainsKey(hasOkashi)) {
            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].Add(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