結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー kuuso1kuuso1
提出日時 2016-11-19 01:36:58
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 393 ms / 2,000 ms
コード長 3,114 bytes
コンパイル時間 2,206 ms
コンパイル使用メモリ 113,160 KB
実行使用メモリ 55,280 KB
最終ジャッジ日時 2023-09-02 12:55:14
合計ジャッジ時間 11,551 ms
ジャッジサーバーID
(参考情報)
judge16 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 64 ms
21,660 KB
testcase_01 AC 64 ms
21,712 KB
testcase_02 AC 64 ms
23,716 KB
testcase_03 AC 65 ms
21,716 KB
testcase_04 AC 67 ms
21,776 KB
testcase_05 AC 67 ms
21,624 KB
testcase_06 AC 67 ms
21,732 KB
testcase_07 AC 64 ms
21,668 KB
testcase_08 AC 67 ms
23,620 KB
testcase_09 AC 67 ms
21,656 KB
testcase_10 AC 65 ms
19,692 KB
testcase_11 AC 65 ms
21,748 KB
testcase_12 AC 66 ms
19,772 KB
testcase_13 AC 105 ms
32,612 KB
testcase_14 AC 115 ms
31,404 KB
testcase_15 AC 191 ms
39,440 KB
testcase_16 AC 266 ms
39,988 KB
testcase_17 AC 281 ms
42,880 KB
testcase_18 AC 99 ms
30,332 KB
testcase_19 AC 347 ms
53,180 KB
testcase_20 AC 162 ms
36,628 KB
testcase_21 AC 356 ms
52,020 KB
testcase_22 AC 169 ms
34,380 KB
testcase_23 AC 352 ms
55,280 KB
testcase_24 AC 125 ms
32,520 KB
testcase_25 AC 339 ms
52,016 KB
testcase_26 AC 95 ms
26,372 KB
testcase_27 AC 275 ms
41,924 KB
testcase_28 AC 242 ms
42,676 KB
testcase_29 AC 170 ms
32,204 KB
testcase_30 AC 356 ms
50,868 KB
testcase_31 AC 109 ms
30,712 KB
testcase_32 AC 110 ms
27,440 KB
testcase_33 AC 393 ms
54,152 KB
testcase_34 AC 380 ms
49,056 KB
testcase_35 AC 370 ms
49,880 KB
testcase_36 AC 374 ms
52,380 KB
testcase_37 AC 371 ms
53,572 KB
testcase_38 AC 369 ms
51,792 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;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		Pair[] P = new Pair[N];
		Dictionary<long,int> dic = new Dictionary<long,int>();
		
		for(int i=0;i<N;i++){
			P[i] = new Pair(T[i],D[i],i);
			if(dic.ContainsKey(D[i]) == false) dic.Add(D[i],0);
			dic[D[i]]++;
		}
		
		Array.Sort(P,(p,q) => -p.D.CompareTo(q.D));
		bool[] forbid = new bool[N];
		for(int i=0;i<N;i++){
			var idx = P[i].Idx;
			var d = P[i].D;
			var t = P[i].T;
			if(forbid[idx])break;
			dic[d]--;
			int j = idx;
			while(j>=0 && T[idx] - T[j] < K){
				forbid[j] = true;
				j--;
			}
			j = idx;
			while(j<N && T[j] - T[idx] < K){
				forbid[j] = true;
				j++;
			}
		}
		
		long yukiMin = (long)2e9;;
		for(int i=0;i<N;i++){
			if(dic[P[i].D] != 0)break;
			yukiMin = P[i].D;
		}
		
		long ameMax = 0;
		for(int i=0;i<N;i++){
			if(D[i] >= yukiMin)continue;
			ameMax = Math.Max(ameMax,D[i]);
		}
		
		long yukiDo = 0;
		bool[] used = new bool[N];
		forbid = new bool[N];
		for(int i=0;i<N;i++){
			if(D[i] >= yukiMin){
				used[i] = true;
				int j=i-1;
				while(j>=0 && T[i] - T[j] < K){
					forbid[j] = true;
					j--;
				}
				yukiDo += D[i];
			}
		}
		
		//Console.WriteLine("forbid:{0}",String.Join(" ",forbid));
		//Console.WriteLine("used  :{0}",String.Join(" ",used));
		
		int[] nxt = new int[N];
		int nn=0;
		for(int i=0;i<N;i++){
			while(nn<N && T[nn] - T[i] < K)nn++;
			nxt[i] = nn;
		}
		
		long[] dp = new long[N+1];
		for(int i=0;i<N;i++){
			if(forbid[i]){
				dp[i+1] = Math.Max(dp[i],dp[i+1]);
			}else if(used[i]){
				dp[nxt[i]] = dp[i];
				i = nxt[i] - 1;
			}else{
				dp[i+1] = Math.Max(dp[i],dp[i+1]);
				dp[nxt[i]] = Math.Max(dp[nxt[i]],dp[i]+D[i]);
			}
		}
		
		//Console.WriteLine("Dsum = {0}",D.Sum());
		//Console.WriteLine("yukiDo = {0}",yukiDo);
		//Console.WriteLine("dp = {0}",String.Join(" ",dp));
		
		long ameDo = D.Sum() - yukiDo - dp[N];
		//long ameDo = D.Sum() - dp[N];
		Console.WriteLine("{0}\n{1}",ameMax,ameDo);
		
	}
	
	class Pair{
		public long T,D;
		public int Idx;
		public Pair(long t,long d,int i){
			T = t; D= d; Idx = i;
		}
	}
	
	int N,K;
	long[] T;
	long[] D;
	public Sol(){
		var d = ria();
		N = d[0]; K = d[1];
		T = new long[N];
		D = new long[N];
		for(int i=0;i<N;i++){
			var dd = rla();
			T[i] = dd[0];
			D[i] = dd[1];
		}
	}
	

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}

0