結果
問題 |
No.649 ここでちょっとQK!
|
ユーザー |
![]() |
提出日時 | 2018-02-09 23:57:08 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,330 bytes |
コンパイル時間 | 1,142 ms |
コンパイル使用メモリ | 115,848 KB |
実行使用メモリ | 51,544 KB |
最終ジャッジ日時 | 2024-10-09 06:12:01 |
合計ジャッジ時間 | 6,414 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | -- * 4 |
other | AC * 4 TLE * 1 -- * 27 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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(); } }