暴力89分
Java 代码
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
int d = scanner.nextInt();
int k = scanner.nextInt();
Comment[] comments = new Comment[n];
for(int i = 0 ; i < n; i++){
int time = scanner.nextInt();
int id = scanner.nextInt();
comments[i] = new Comment(time, id);
}
Arrays.sort(comments);
TreeSet<Integer> res = new TreeSet<>();
HashMap<Integer, Integer> count;
for(int i = 0 ; i < n; i++){
count = new HashMap<>();
int left = comments[i].time;
for(int j = i;j < n && comments[j].time - left < d; j++){
int id = comments[j].id;
if(count.containsKey(id)){
Integer integer = count.get(id);
count.put(id, integer+1);
}else{
count.put(id, 1);
}
}
for (Integer key : count.keySet()) {
if(count.get(key) >= k){
res.add(key);
}
}
}
Iterator<Integer> iterator = res.iterator();
while (iterator.hasNext()){
System.out.println(iterator.next());
}
scanner.close();
}
}
class Comment implements Comparable<Comment>{
int time;
int id;
public Comment(int time, int id) {
this.time = time;
this.id = id;
}
@Override
public int compareTo(Comment o) {
return Integer.compare(this.time, o.time);
}
}