結果
問題 |
No.448 ゆきこーだーの雨と雪 (3)
|
ユーザー |
![]() |
提出日時 | 2016-11-19 01:36:58 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 334 ms / 2,000 ms |
コード長 | 3,114 bytes |
コンパイル時間 | 1,247 ms |
コンパイル使用メモリ | 114,504 KB |
実行使用メモリ | 57,700 KB |
最終ジャッジ日時 | 2024-06-11 19:34:53 |
合計ジャッジ時間 | 7,843 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 35 |
コンパイルメッセージ
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; 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));} }