-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path747.cpp
More file actions
121 lines (112 loc) · 2.08 KB
/
747.cpp
File metadata and controls
121 lines (112 loc) · 2.08 KB
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/*****************************************
* (This comment block is added by the Judge System)
* Submission ID: 70599
* Submitted at: 2018-10-29 21:30:51
*
* User ID: 539
* Username: 55211931
* Problem ID: 747
* Problem Name: Boring job
*/
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
class num {
public:
int no;
int pos;
num(int n, int p)
{
no = n;
pos = p;
}
};
int main()
{
int times;
cin >> times;
for (int i = 0; i < times; i++)
{
int magic;
int numsize;
list<num> lt;
cin >> numsize >> magic;
for (int i = 0; i < numsize; i++)
{
int nu;
cin >> nu;
lt.push_back(num(nu, i + 1));
}
list<int> result;
while (!lt.empty())
{
int max = lt.front().no;
int pos = lt.front().pos;
list<num>temp;
if (lt.size() >= magic)
{
for (int i = 0; i < magic; i++)
{
if (lt.front().no > max)
{
max = lt.front().no;
pos = lt.front().pos;
}
//else if (lt.front().no == max)
//{
// if (lt.front().pos < pos)
// {
// pos = lt.front().pos;
// }
//}
temp.push_back(num(lt.front().no, lt.front().pos));
lt.pop_front();
}
}
else
{
while (!lt.empty())
{
if (lt.front().no > max)
{
max = lt.front().no;
pos = lt.front().pos;
}
/*else if (lt.front().no == max)
{
if (lt.front().pos < pos)
{
pos = lt.front().pos;
}
}*/
temp.push_back(num(lt.front().no, lt.front().pos));
lt.pop_front();
}
}
result.push_back(pos);
while (!temp.empty())
{
if (temp.front().pos != pos)
{
lt.push_back(num(temp.front().no - 1, temp.front().pos));
temp.pop_front();
}
else
{
temp.pop_front();
}
}
}
cout << result.front();
result.pop_front();
while(!result.empty())
{
cout << " "<< result.front() ;
result.pop_front();
}
cout << endl;
}
return 0;
}