結果

問題 No.1715 Dinner 2
ユーザー kakel-san
提出日時 2021-10-22 22:16:06
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,197 bytes
コンパイル時間 3,310 ms
コンパイル使用メモリ 113,116 KB
実行使用メモリ 53,728 KB
最終ジャッジ日時 2024-09-23 05:51:59
合計ジャッジ時間 26,538 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 35 WA * 3
権限があれば一括ダウンロードができます
コンパイルメッセージ
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 static System.Console;
using System.Linq;

class yuki319
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static int[][] NArr(int n) => Enumerable.Repeat(0, n).Select(_ => NList).ToArray();
    static void Main()
    {
        var c = NList;
        var (n, d) = (c[0], c[1]);
        var menu = NArr(n);

        var pmlist = new List<Pair>[100001];
        for (var i = 0; i < pmlist.Length; ++i) pmlist[i] = new List<Pair>();
        for (var i = 0; i < menu.Length; ++i) pmlist[menu[i][0]].Add(new Pair(i, menu[i][1] - menu[i][0]));

        for (var i = 1; i < pmlist.Length; ++i)
        {
            pmlist[i].AddRange(pmlist[i - 1]);
            pmlist[i].Sort();
            pmlist[i] = pmlist[i].Take(2).ToList();
        }

        var ok = -100000000;
        var ng = 0;
        while (ng - ok > 1)
        {
            var center = (ok + ng) / 2;
            var tmp = 0;
            var flg = true;
            var prev = -1;
            for (var i = 0; i < d; ++i)
            {
                var pow = Math.Min(100000, tmp - center);
                if (pow < 0 || pmlist[pow].Count == 0 || pmlist[pow].Count == 1 && pmlist[pow][0].Pos == prev)
                {
                    flg = false;
                    break;
                }
                if (pmlist[pow][0].Pos != prev)
                {
                    prev = pmlist[pow][0].Pos;
                    tmp += pmlist[pow][0].Val;
                }
                else
                {
                    prev = pmlist[pow][1].Pos;
                    tmp += pmlist[pow][1].Val;
                }
            }
            if (flg) ok = center;
            else ng = center;
        }
        WriteLine(ok);
    }
    class Pair : IComparable<Pair>
    {
        public int Pos;
        public int Val;
        public Pair(int pos, int val)
        {
            Pos = pos; Val = val;
        }
        public int CompareTo(Pair b)
        {
            return b.Val.CompareTo(Val);
        }
    }
}
0