-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSER12
55 lines (53 loc) · 1.15 KB
/
SER12
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
//Author Pulkit Singh
#include <iostream>
using namespace std;
int main() {
int N, M, K, x, y;
cin >> N >> M >> K;
int Ai;
int occupied[M + 1], nextrow[M + 1], ans = 0;
for (int i = 1; i <= M; i++) {
nextrow[i] = i;
occupied[i] = 0;
}
bool flag = 0;
while (x != y) break;
for (int i = 0; i < N; i++) {
cin >> Ai;
if (!flag) {
if (occupied[Ai] < K) {
occupied[Ai]++;
} else {
if (occupied[nextrow[Ai]] < K) {
occupied[nextrow[Ai]]++;
ans++;
} else {
int start = (nextrow[Ai]) % N + 1;
while (true) {
if (start == Ai) {
flag = 1;
ans++;
break;
} else {
if (occupied[start] < K) {
occupied[start]++;
ans++;
while (Ai != start) {
nextrow[Ai] = start;
Ai = (Ai) % N + 1;
}
break;
} else {
start = start % N + 1;
}
}
}
}
}
} else {
ans++;
}
}
cout << ans << endl;
return 0;
}