結果
問題 | No.448 ゆきこーだーの雨と雪 (3) |
ユーザー |
![]() |
提出日時 | 2016-11-15 18:49:29 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 311 ms / 2,000 ms |
コード長 | 4,206 bytes |
コンパイル時間 | 843 ms |
コンパイル使用メモリ | 118,760 KB |
実行使用メモリ | 38,272 KB |
最終ジャッジ日時 | 2024-06-11 19:27:19 |
合計ジャッジ時間 | 8,955 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.Generic; using System.Linq; using System.Linq.Expressions; using System.IO; class Program { static StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false }; const int M = 1000000007; const double eps = 1e-9; static int[] dd = { 0, 1, 0, -1, 0 }; static void Main() { int n, k; sc.Multi(out n, out k); var t = new int[n]; var d = new int[n]; long sum = 0; for (int i = 0; i < n; i++) { sc.Multi(out t[i], out d[i]); sum += d[i]; } long bestsum = 0; int ng = -1, ok = M; while (ng + 1 < ok) { int m = (ng + ok) >> 1; long msum = 0; var yukiproc = new List<int>(); for (int i = 0; i < n; i++) { if (d[i] > m) { if (yukiproc.Count > 0 && t[i] - t[yukiproc[yukiproc.Count - 1]] < k) goto A; yukiproc.Add(i); msum += d[i]; } } var canwakeup = new List<int>(); int j = 0; for (int i = 0; i < n; i++) { if ((j >= yukiproc.Count || Math.Abs(t[yukiproc[j]] - t[i]) >= k) && (j >= yukiproc.Count - 1 || Math.Abs(t[yukiproc[j + 1]] - t[i]) >= k)) canwakeup.Add(i); if (j < yukiproc.Count - 1 && i == yukiproc[j + 1]) ++j; } var dp = new long[canwakeup.Count + 1]; dp[0] = 0; j = -1; for (int i = 0; i < canwakeup.Count; i++) { while (t[canwakeup[i]] - t[canwakeup[j + 1]] >= k) ++j; dp[i + 1] = Math.Max(dp[i], dp[j + 1] + d[canwakeup[i]]); } ok = m; bestsum = sum - msum - dp[canwakeup.Count]; continue; A: ng = m; } sw.WriteLine(ok); sw.WriteLine(bestsum); sw.Flush(); } static void DBG<T>(params T[] a) => Console.WriteLine(string.Join(" ", a)); static void DBG(params object[] a) => Console.WriteLine(string.Join(" ", a)); static void Prt<T>(params T[] a) => sw.WriteLine(string.Join(" ", a)); static void Prt(params object[] a) => sw.WriteLine(string.Join(" ", a)); } class scanCHK : sc { public static new string Str { get { var s = Console.ReadLine(); return s == s.Trim() ? s : ""; } } } class sc { public static int Int => int.Parse(Str); public static long Long => long.Parse(Str); public static double Double => double.Parse(Str); public static string Str => Console.ReadLine().Trim(); public static int[] IntArr => StrArr.Select(int.Parse).ToArray(); public static long[] LongArr => StrArr.Select(long.Parse).ToArray(); public static double[] DoubleArr => StrArr.Select(double.Parse).ToArray(); public static string[] StrArr => Str.Split(); static bool eq<T, U>() => typeof(T).Equals(typeof(U)); static T ct<T, U>(U inp) => (T)Convert.ChangeType(inp, typeof(T)); static T cv<T>(string inp) => eq<T, int>() ? ct<T, int>(int.Parse(inp)) : eq<T, long>() ? ct<T, long>(long.Parse(inp)) : eq<T, double>() ? ct<T, double>(double.Parse(inp)) : eq<T, char>() ? ct<T, char>(inp[0]) : ct<T, string>(inp); public static void Multi<T>(out T a) => a = cv<T>(Str); public static void Multi<T, U>(out T a, out U b) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); } public static void Multi<T, U, V>(out T a, out U b, out V c) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); } public static void Multi<T, U, V, W>(out T a, out U b, out V c, out W d) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); } public static void Multi<T, U, V, W, X>(out T a, out U b, out V c, out W d, out X e) { var ar = StrArr; a = cv<T>(ar[0]); b = cv<U>(ar[1]); c = cv<V>(ar[2]); d = cv<W>(ar[3]); e = cv<X>(ar[4]); } }