-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1966.cpp
73 lines (69 loc) · 1.15 KB
/
1966.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
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
int arr[101] = { 0, };
int ans = 0;
int length = 0;
int flag;
int max(int *a) {
int M = a[0];
int cnt = 1;
for (int i = 1; a[i]; i++) {
if (a[i] > M) M = a[i];
cnt++;
}
length = cnt;
return M;
}
void cng(int *a){
int cnt = 0;
int temp[101];
for (int i = 1; a[i]; i++) {
temp[i - 1] = a[i];
cnt++;
}
temp[cnt] = a[0];
if (flag == 0)
flag = length - 1;
else flag -= 1;
for (int i = 0; a[i]; i++)
arr[i] = temp[i];
}
void pop(int *a) {
int temp[101] = { 0, };
for (int i = 1; a[i]; i++) {
temp[i - 1] = a[i];
}
temp[length - 1] = 0;
ans++;
length--;
flag--;
for (int i = 0; a[i]; i++)
arr[i] = temp[i];
}
int main() {
int T;
int N;
int Mx;
scanf("%d", &T);
for (int i = 0; i < T; i++) {
scanf("%d %d", &N, &flag);
for (int j = 0; j < N; j++)
scanf("%d", &arr[j]);
while (1) {
Mx = max(arr);
if (arr[0] == Mx) {
if (flag == 0) {
pop(arr);
break;
}
pop(arr);
}
else
cng(arr);
}
printf("%d\n", ans);
ans = 0;
for (int i = 0; i < 101; i++)
arr[i] = 0;
}
}