-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathA1109.cpp
62 lines (58 loc) · 1.2 KB
/
A1109.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
const int MAXN = 10000 + 10;
int N, K;
struct Person{
string name;
int height;
} person[MAXN];
bool cmp(const Person &p1, const Person &p2){
if(p1.height != p2.height) return p1.height < p2.height;
else return p1.name > p2.name;
}
vector<string> ans[11];
int main(){
scanf("%d%d", &N, &K);
for(int i = 0; i < N; ++i){
char name[8];
int height;
scanf("%s%d", name, &height);
person[i].name = name;
person[i].height = height;
}
sort(person, person+N, cmp);
int num = N/K;
for(int i = 0; i < K; ++i){
bool flag = true;
if(i != K-1){
for(int j = (i+1)*num-1; j >= i*num; --j){
if(flag == true){
ans[i].push_back(person[j].name);
}else{
ans[i].insert(ans[i].begin(), person[j].name);
}
flag = !flag;
}
}else{
for(int j = N-1; j >= i*num; --j){
if(flag == true){
ans[i].push_back(person[j].name);
}else{
ans[i].insert(ans[i].begin(), person[j].name);
}
flag = !flag;
}
}
}
for(int i = K-1; i >= 0; --i){
for(int j = 0; j < ans[i].size(); ++j){
if(j != 0) printf(" ");
printf("%s", ans[i][j].c_str());
}
printf("\n");
}
return 0;
}