結果

問題 No.448 ゆきこーだーの雨と雪 (3)
ユーザー kuuso1kuuso1
提出日時 2016-11-19 00:53:38
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 3,426 bytes
コンパイル時間 773 ms
コンパイル使用メモリ 115,872 KB
実行使用メモリ 59,552 KB
最終ジャッジ日時 2024-05-04 20:16:09
合計ジャッジ時間 7,768 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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;

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[i],dp[nxt[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];
		Console.WriteLine("{0} {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));}
}

class BIT{
	int MM;
	int n;
	long[] bit;
	public BIT(int n_){
		n=n_;
		MM=1<<18;
		while(MM<n*2)MM<<=1;
		bit=new long[MM+1];
	}
	//1-origin!!
	public void Add(int i,int x){
		while(i<=n){
			bit[i]+=x;
			i+=(i&-i);
		}
	}
	
	// i=>sum(a_1,...,a_i)
	// i=0 -> return 0;
	public long Sum(int i){
		long s=0;
		while(i>0){
			s+=bit[i];
			i-= (i&-i);
		}
		return s;
	}
}
0