結果
| 問題 |
No.54 Happy Hallowe'en
|
| コンテスト | |
| ユーザー |
14番
|
| 提出日時 | 2016-06-13 05:04:44 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 2,947 bytes |
| コンパイル時間 | 1,014 ms |
| コンパイル使用メモリ | 108,416 KB |
| 実行使用メモリ | 24,576 KB |
| 最終ジャッジ日時 | 2024-10-09 13:07:28 |
| 合計ジャッジ時間 | 2,399 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 3 RE * 16 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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();
}
}
14番