Skip to content

Latest commit

 

History

History
73 lines (61 loc) · 1.24 KB

1129.md

File metadata and controls

73 lines (61 loc) · 1.24 KB

1129

image.png

#include <cstdio>
#include <set>
using namespace std;

int N, K;
const int MAX_N = 50000 + 5;
const int MAX_K = 10 + 5;
int book[MAX_N] = { 0 };
struct Node {
	int val, num;
	bool operator < (const Node& a) const {
		return a.num == num ? val<a.val : num>a.num;
	}
};

int main() {
	scanf("%d%d", &N, &K);
	set<Node> s;
	for (int i = 0; i < N; i++) {
		int num;
		scanf("%d", &num);
		if (i != 0) {
			printf("%d:", num);
			int temp = 0;
			for (auto it = s.begin(); temp < K && it != s.end(); it++, temp++) {
				printf(" %d", it->val);
			}
			printf("\n");
		}
		auto it = s.find(Node{ num, book[num] });
		if (it != s.end()) {
			s.erase(it);
		}
		book[num]++;
		s.insert(Node{ num,book[num] });
	}
	return 0;
}

/*
Sample Input:
12 3
3 5 7 5 5 3 2 1 8 3 8 12
Sample Output:
5: 3
7: 3 5
5: 3 5 7
5: 5 3 7
3: 5 3 7
2: 5 3 7
1: 5 3 2
8: 5 3 1
3: 5 3 1
8: 3 5 1
12: 3 5 8
*/

References