-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMex_imizing.cpp
More file actions
42 lines (35 loc) · 830 Bytes
/
Mex_imizing.cpp
File metadata and controls
42 lines (35 loc) · 830 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
#include <iostream>
int size, r;
int cnt[10005];
int freq[10005];
int mex = 0;
int main()
{
std::cin >> size >> r;
for (int i = 0; i < size; i++)
{
std::cin >> cnt[i];
}
for (int i = 0; i < size; i++)
{
int cur_rmd = cnt[i] % r;
freq[cur_rmd]++;
while (true)
{
int rmd = mex % r;
// std::cout << "remainder of mex: " << rmd << " cur_rmd is " << cur_rmd << std::endl;
// std::cout << "freq[cur_rmd]: " << freq[cur_rmd] << " freq[rmd] is " << freq[rmd] << std::endl;
if (freq[rmd] > 0)
{
freq[rmd]--;
mex = mex + 1;
}
else
{
break;
}
}
std::cout << mex << std::endl;
}
return 0;
}