-
Notifications
You must be signed in to change notification settings - Fork 2
/
1055.cpp
40 lines (36 loc) · 991 Bytes
/
1055.cpp
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
35
36
37
38
39
40
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
using namespace std;
struct Person {
string name;
int height;
};
vector<Person> people;
void formate(int &i, int num, deque<string> &q) {
q.push_back(people[i++].name);
while (q.size() < num) {
if (q.size() % 2) q.push_front(people[i++].name);
else q.push_back (people[i++].name);
}
}
int main() {
int n, k;
cin >> n >> k;
people.resize(n);
for (int i = 0; i < n; i++)
cin >> people[i].name >> people[i].height;
sort(people.begin(), people.end(), [](Person a, Person b) {
return a.height != b.height ? a.height > b.height : a.name < b.name;
});
int i = 0;
while (i < n) {
deque<string> q;
if (i == 0) formate(i, n / k + n % k, q);
else formate(i, n / k, q);
for (int j = 0; j < q.size(); j++)
cout << q[j] << (j < q.size() - 1 ? ' ' : '\n');
}
return 0;
}