https://www.patest.cn/contests/pat-a-practise/1109
#include <iostream>
#include<cstdio>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;
typedef struct peo {
string name;
int height;
friend bool operator < (struct peo a, struct peo b) {
return a.height != b.height ? a.height < b.height: a.name > b.name;
}
} Peo;
Peo peos[10001];
int n, k;
void pivots(int l, int r) {
int m = r - l;
vector<string> temp(m);// string[m];
int cur = r - 1, mid = m/ 2 ;
int midl = mid - 1, midr = mid + 1;
temp[mid] = peos[cur--].name;
while (cur >= l) {
if (cur >= l) temp[midl--] = peos[cur--].name;
if (cur >= l) temp[midr++] = peos[cur--].name;
}
for (size_t i = 0; i < m; i++)
{
printf("%s%c", temp[i].c_str(), i == m - 1 ? '\n' : ' ');
}
}
int main()
{
cin >> n>>k;
for (size_t i = 0; i < n; i++)
{
cin >> peos[i].name>>peos[i].height;
}
sort(peos, peos + n);
int rsp = n / k;
for (int i = k-1; i >=0; i--)
{
if (i == k - 1) {
pivots(i*rsp, n);
}
else {
pivots(i*rsp, (i + 1)*rsp);
}
}
return 0;
}