-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp1583.cpp
103 lines (85 loc) · 1.68 KB
/
p1583.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <bits/stdc++.h>
using namespace std;
int n(0), k(0), e[11], _w(0);
struct Person{
int serialno;
int w;
}person[20001];
void quickSortWDesc(int low, int high)
{
int i = low;
int j = high;
int pivot = person[(low + high) / 2].w;
do{
while(person[i].w > pivot) i++;
while(person[j].w < pivot) j--;
if(i <= j){
swap(person[i], person[j]);
i++;
j--;
}
}while(i <= j) ;
if(low < j) quickSortWDesc(low, j);
if(i < high) quickSortWDesc(i, high);
}
void quickSortSerialnoAsc(int low, int high)
{
int i = low;
int j = high;
int pivot = person[(low + high) / 2].serialno;
do{
while(person[i].serialno < pivot) i++;
while(person[j].serialno > pivot) j--;
if(i <= j){
swap(person[i], person[j]);
i++;
j--;
}
}while(i <= j) ;
if(low < j) quickSortSerialnoAsc(low, j);
if(i < high) quickSortSerialnoAsc(i, high);
}
int main(void){
cin >> n >> k;
for(int i = 1; i <= 10; i++){
cin >> e[i];
}
for(int i = 1; i <= n; i++){
cin >> _w;
person[i].serialno = i;
person[i].w = _w;
}
quickSortWDesc(1, n);
for(int i = 1; i <= n; i++){
int m = i;
while(person[m + 1].w == person[m].w) m++;
if(i != m){
quickSortSerialnoAsc(i, m);
i = m;
}
}
for(int i = 1; i <= n; i++){
person[i].w += e[(i - 1) % 10 + 1];
}
/*
for(int i = 1; i <= n; i++){
cout << person[i].w << ' ';
}
cout << endl;
*/
quickSortWDesc(1, n);
int j = k;
while(person[j + 1].w == person[j].w) j++;
for(int i = 1; i <= j; i++){
int m = i;
while(person[m + 1].w == person[m].w) m++;
if(i != m){
quickSortSerialnoAsc(i, m);
i = m;
}
}
for(int i = 1; i <= k; i++){
cout << person[i].serialno << ' ';
}
return 0;
}