結果
| 問題 | No.2804 Fixer And Ratism |
| コンテスト | |
| ユーザー |
tenten
|
| 提出日時 | 2024-07-17 09:50:30 |
| 言語 | Java (openjdk 23) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,993 bytes |
| 記録 | |
| コンパイル時間 | 5,739 ms |
| コンパイル使用メモリ | 83,532 KB |
| 実行使用メモリ | 61,440 KB |
| 最終ジャッジ日時 | 2024-07-17 09:51:15 |
| 合計ジャッジ時間 | 18,360 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 11 WA * 20 |
ソースコード
import java.io.*;
import java.util.*;
import java.util.function.*;
import java.util.stream.*;
public class Main {
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner();
int n = sc.nextInt();
int q = sc.nextInt();
TreeSet<Student> students = new TreeSet<>();
Map<String, Student> map = new HashMap<>();
List<Student> ans = new ArrayList<>();
while (q-- > 0) {
int type = sc.nextInt();
if (type == 1) {
String name = sc.next();
int rate = sc.nextInt();
map.put(name, new Student(name, rate));
students.add(map.get(name));
while (students.size() > n) {
ans.add(students.pollLast());
}
} else if (type == 2) {
n -= sc.nextInt();
while (students.size() > n) {
ans.add(students.pollLast());
}
} else {
String name = sc.next();
n += sc.nextInt();
students.remove(map.get(name));
map.get(name).fix();
students.add(map.get(name));
}
}
System.out.println(ans.stream().map(x -> x.toString()).collect(Collectors.joining("\n")));
}
static class Student implements Comparable<Student> {
String name;
int value;
int fixed;
public Student(String name, int value) {
this.name = name;
this.value = value;
}
public void fix() {
fixed = 1;
}
public int hashCode() {
return name.hashCode();
}
public boolean equals(Object o) {
Student s = (Student)o;
return name.equals(s.name);
}
public int compareTo(Student another) {
return fixed == another.fixed ? another.value - value : another.fixed - fixed;
}
public String toString() {
return name;
}
}
}
class Scanner {
BufferedReader br;
StringTokenizer st = new StringTokenizer("");
StringBuilder sb = new StringBuilder();
public Scanner() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
} catch (Exception e) {
}
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String next() {
try {
while (!st.hasMoreTokens()) {
st = new StringTokenizer(br.readLine());
}
} catch (Exception e) {
e.printStackTrace();
} finally {
return st.nextToken();
}
}
}
tenten