Official

B - Qualification Contest Editorial by en_translator


The nicknames of the top \(K\) participants are \(S_1, S_2, \ldots, S_K\).
Thus, it is sufficient to sort \((S_1, S_2, \ldots, S_K)\) in ascending order.
This can be achieved by a function that sorts an array of strings in lexicographical order, which are standard function defined in many languages with name “sort”.

Sample code (C++)

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	vector<string> a;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;
		if (i < k) a.push_back(s);
	}
	sort(a.begin(), a.end());
	for (string s : a) cout << s << '\n';
}

posted:
last update: