#include <iostream>
#include <vector>
#include <map>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
struct node{
string name;
int h;
};
bool cmp(node &a, node &b){
if(a.h == b.h) return a.name < b.name;
else return a.h > b.h;
}
int main()
{
int n, m, k, cnt = 0;
cin >> n >> k;
vector<node> v(n);
for(int i = 0; i < n; i++){
cin >> v[i].name >> v[i].h;
}
sort(v.begin(), v.end(), cmp);
for(int i = 0; i < k; i++){
if(i == 0) m = n / k + n % k;
else m = n / k;
int t = m, flag = 0;
if(m % 2 != 0) t = m-1;
for(int j = cnt + t - 1; j > cnt; j = j - 2){
if(j != cnt + t - 1) cout << ' ';
cout << v[j].name;
flag = 1;
}
for(int j = cnt; j < cnt + m; j = j + 2 ){
if(flag){ cout << ' ';}
else flag = 1;
cout << v[j].name;
}
cnt += m;
cout << endl;
}
return 0;
}
}
1109. Group Photo (25)
最新推荐文章于 2019-09-04 08:41:54 发布