-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1055.cpp
More file actions
63 lines (60 loc) · 901 Bytes
/
1055.cpp
File metadata and controls
63 lines (60 loc) · 901 Bytes
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<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;
struct inf{
string name;
int h;
};
bool cmp(inf a, inf b){
if(a.h>b.h)
return a.h>b.h;
if(a.h==b.h&&a.name!=b.name)
return a.name<b.name;
return false;
}
int main(){
int n,k;
cin>>n>>k;
inf *a = new inf [n];
for(int i=0;i<n;i++){
cin>>a[i].name>>a[i].h;
}
sort(a,a+n,cmp);
int max=0;
for(int i=0;i<k;i++){
int m=0;
if(i==0)
m = n/k+n%k;
else
m=n/k;
if(m==1){
cout<<a[max].name;
}else{
int t=2*(m/2)-1;
while(t>0)
{
cout<<a[max+t].name<<" ";
t-=2;
}
if(max==max+2*(m-1-m/2))
cout<<a[max].name;
else
cout<<a[max].name<<" ";
t=2;
while(t<=2*(m-1-m/2))
{
if(t!=2*(m-1-m/2))
cout<<a[max+t].name<<" ";
else
cout<<a[max+t].name;
t+=2;
}
}
cout<<endl;
max = max+m;
}
system("pause");
return 0;
}