結果

問題 No.951 【本日限定】1枚頼むともう1枚無料!
ユーザー fgwiebfaoishfgwiebfaoish
提出日時 2019-12-27 19:58:30
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 861 ms / 2,000 ms
コード長 3,129 bytes
コンパイル時間 1,173 ms
コンパイル使用メモリ 119,288 KB
実行使用メモリ 20,832 KB
最終ジャッジ日時 2024-04-17 11:51:57
合計ジャッジ時間 25,000 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
19,072 KB
testcase_01 AC 33 ms
19,200 KB
testcase_02 AC 34 ms
19,072 KB
testcase_03 AC 33 ms
19,200 KB
testcase_04 AC 33 ms
18,688 KB
testcase_05 AC 34 ms
19,072 KB
testcase_06 AC 34 ms
18,944 KB
testcase_07 AC 34 ms
19,072 KB
testcase_08 AC 33 ms
18,944 KB
testcase_09 AC 51 ms
19,200 KB
testcase_10 AC 43 ms
19,072 KB
testcase_11 AC 43 ms
18,944 KB
testcase_12 AC 182 ms
19,560 KB
testcase_13 AC 607 ms
20,576 KB
testcase_14 AC 117 ms
19,200 KB
testcase_15 AC 123 ms
19,328 KB
testcase_16 AC 166 ms
19,440 KB
testcase_17 AC 201 ms
20,556 KB
testcase_18 AC 33 ms
19,072 KB
testcase_19 AC 33 ms
19,072 KB
testcase_20 AC 33 ms
18,944 KB
testcase_21 AC 41 ms
18,816 KB
testcase_22 AC 37 ms
19,200 KB
testcase_23 AC 38 ms
19,200 KB
testcase_24 AC 749 ms
20,660 KB
testcase_25 AC 846 ms
20,696 KB
testcase_26 AC 861 ms
20,572 KB
testcase_27 AC 857 ms
20,832 KB
testcase_28 AC 754 ms
20,444 KB
testcase_29 AC 754 ms
20,700 KB
testcase_30 AC 34 ms
19,200 KB
testcase_31 AC 33 ms
19,072 KB
testcase_32 AC 37 ms
19,200 KB
testcase_33 AC 39 ms
19,200 KB
testcase_34 AC 44 ms
19,328 KB
testcase_35 AC 747 ms
20,584 KB
testcase_36 AC 745 ms
20,580 KB
testcase_37 AC 848 ms
20,656 KB
testcase_38 AC 843 ms
20,784 KB
testcase_39 AC 847 ms
20,776 KB
testcase_40 AC 855 ms
20,700 KB
testcase_41 AC 855 ms
20,444 KB
testcase_42 AC 856 ms
20,444 KB
testcase_43 AC 853 ms
20,708 KB
testcase_44 AC 852 ms
20,696 KB
testcase_45 AC 856 ms
20,828 KB
testcase_46 AC 752 ms
20,832 KB
testcase_47 AC 754 ms
20,708 KB
testcase_48 AC 755 ms
20,572 KB
testcase_49 AC 753 ms
20,568 KB
testcase_50 AC 750 ms
20,696 KB
testcase_51 AC 756 ms
20,708 KB
testcase_52 AC 510 ms
20,664 KB
testcase_53 AC 593 ms
20,536 KB
testcase_54 AC 423 ms
20,328 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.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static void Main(){
		Sc sc=new Sc();
		var s=sc.Ia;
		var a=new int[s[0]+1][];
		var c=new int[s[0]+1];
		var dp=new int[2][][];
		dp[0]=new int[][]{new int[s[1]+1],new int[s[1]+1]};
		dp[1]=new int[][]{new int[s[1]+1],new int[s[1]+1]};
		a[0]=new int[]{0,0};
		for(int i = 1;i<=s[0];i++) {a[i]=sc.Ia;}
		a=a.OrderBy(x=>x[0]).ThenBy(x=>x[1]).ToArray();
		dp[0][0][0]=dp[1][0][0]=dp[0][1][0]=dp[1][1][0]=1;
		for(int i = 1;i<=s[0];i++) {
			for(int j = 0;j<2;j++) {
				for(int k = s[1];k>=0;k--) {
					if(j==0){
						if(dp[(i&1)^1][j^1][k]>0){
							dp[i&1][j][k]=Max(dp[i&1][j][k],dp[(i&1)^1][j^1][k]+a[i][1]);
						}
						dp[i&1][j][k]=Max(dp[i&1][j][k],dp[(i&1)^1][j][k]);
					}
					else{
						if(k>=a[i][0]&&dp[(i&1)^1][j^1][k-a[i][0]]>0){
							dp[i&1][j][k]=Max(dp[i&1][j][k],dp[(i&1)^1][j^1][k-a[i][0]]+a[i][1]);
						}
						dp[i&1][j][k]=Max(dp[i&1][j][k],dp[(i&1)^1][j][k]);
					}
				}
			}
			dp[i&1][1][0]=1;
		}
		Console.WriteLine("{0}",Max(dp[0][1].Max(),dp[1][1].Max())-1);
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}
0