結果
| 問題 |
No.649 ここでちょっとQK!
|
| コンテスト | |
| ユーザー |
バカらっく
|
| 提出日時 | 2018-02-10 12:59:13 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 3,188 bytes |
| コンパイル時間 | 931 ms |
| コンパイル使用メモリ | 109,440 KB |
| 実行使用メモリ | 33,024 KB |
| 最終ジャッジ日時 | 2024-10-13 07:43:36 |
| 合計ジャッジ時間 | 6,376 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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[] qk = Reader.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
int q = qk[0];
int k = qk[1];
SortedDictionary<long, int> first = new SortedDictionary<long, int>();
SortedDictionary<long, int> second = new SortedDictionary<long, int>();
int itemCount = 0;
StringBuilder ans = new StringBuilder();
for (int i = 0; i < q; i++) {
long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray();
if(inpt[0]==1) {
long num = inpt[1];
if(itemCount>=k-1) {
if(second.Count>0&&num>=second.First().Key) {
if (second.ContainsKey(num))
{
second[num]++;
}
else
{
second.Add(num, 1);
}
} else {
if(first.ContainsKey(num)) {
first[num]++;
} else {
first.Add(num, 1);
}
long tmp = first.Last().Key;
if(--first[tmp]<=0) {
first.Remove(tmp);
}
if(second.ContainsKey(tmp)) {
second[tmp]++;
} else {
second.Add(tmp, 1);
}
}
} else {
if(first.ContainsKey(num)) {
first[num]++;
} else {
first.Add(num, 1);
}
}
itemCount++;
} else {
if(second.Count<=0) {
ans.AppendLine("-1");
} else {
long num = second.First().Key;
ans.AppendLine(num.ToString());
if(--second[num]<=0) {
second.Remove(num);
}
itemCount--;
}
}
}
Console.Write(ans.ToString());
}
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 = @"
10 3
1 3
1 4
1 0
2
1 5
1 2
2
1 10
2
2
";
}
public static void Main(string[] args)
{
#if DEBUG
Reader.IsDebug = true;
#endif
Program prg = new Program();
prg.Proc();
}
}
バカらっく