結果

問題 No.649 ここでちょっとQK!
ユーザー バカらっくバカらっく
提出日時 2018-02-09 23:57:08
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 2,330 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 109,312 KB
実行使用メモリ 29,568 KB
最終ジャッジ日時 2024-04-17 12:10:16
合計ジャッジ時間 6,486 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
24,704 KB
testcase_01 AC 30 ms
18,944 KB
testcase_02 AC 30 ms
19,200 KB
testcase_03 AC 135 ms
24,832 KB
testcase_04 TLE -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.IO;
using System.Linq;
using System.Collections.Generic;
using System.Text;

public class Program
{

    public void Proc()
    {
        int[] inpt = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

        int q = inpt[0];
        int k = inpt[1];

        StringBuilder ans = new StringBuilder();
        for (int i = 0; i < q; i++) {
            long[] tmp = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
            if(tmp[0]==1) {
                long num = tmp[1];
                int idx = GetIdx(0, this.Lst.Count, num);
                this.Lst.Insert(idx, num);
            } else {
                if(this.Lst.Count<k) {
                    ans.AppendLine("-1");
                } else {
                    ans.AppendLine(this.Lst[k-1].ToString());
                    this.Lst.RemoveAt(k-1);
                }
            }
        }
        Console.Write(ans.ToString());
    }

    private List<long> Lst = new List<long>();
    private int GetIdx(int min, int max, long num) {
        if(this.Lst.Count<=0) {
            return 0;
        }
        int mid = (max + min) / 2;
        if(max-min<=1) {
            if (num < this.Lst[min])
            {
                return min;
            } else {
                return max;                
            }
        }
        if(this.Lst[mid]==num) {
            return mid;
        } else if(this.Lst[mid]<num) {
            return GetIdx(mid, max, num);
        } else {
            return GetIdx(min, mid, num);
        }
    } 


    public class Reader
    {
        private static StringReader sr;
        public static bool IsDebug = false;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (sr == null)
                {
                    sr = new StringReader(InputText.Trim());
                }
                return sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        private static string InputText = @"



15 3
1 3
1 4
1 5
2
2
1 10
1 10
1 1
2
1 3
2
1 1000
2
1 0
2


";
    }

    public static void Main(string[] args)
    {
#if DEBUG
        Reader.IsDebug = true;
#endif
        Program prg = new Program();
        prg.Proc();
    }
}
0