-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path1129.cpp
More file actions
34 lines (31 loc) · 788 Bytes
/
1129.cpp
File metadata and controls
34 lines (31 loc) · 788 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <vector>
#include <set>
using namespace std;
struct Node {
int val, cnt;
bool operator<(const Node &b) const {
return cnt != b.cnt ? cnt > b.cnt : val < b.val;
}
};
int main() {
int n, k;
cin >> n >> k;
vector<int> counts(n + 1);
set<Node> nodes;
for (int i = 0; i < n; i++) {
int val;
cin >> val;
if (i != 0) {
int j = 0;
printf("%d:", val);
for (auto it = nodes.begin(); it != nodes.end() && j++ < k; it++)
printf(" %d", it->val);
printf("\n");
}
auto it = nodes.find(Node{val, counts[val]});
if (it != nodes.end()) nodes.erase(it);
nodes.insert(Node{val, ++counts[val]});
}
return 0;
}