-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2232A.cpp
More file actions
61 lines (47 loc) · 1.11 KB
/
Copy path2232A.cpp
File metadata and controls
61 lines (47 loc) · 1.11 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
#include <iostream>
using namespace std;
int main() {
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
long long a[105];
for (int i = 0; i < n; i++) {
cin >> a[i];
}
// Manual sorting (bubble sort)
for (int i = 0; i < n; i++) {
for (int j = i + 1; j < n; j++) {
if (a[i] > a[j]) {
long long temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
int ans = n - 1;
int left = 0;
int i = 0;
while (i < n) {
int freq = 1;
int j = i + 1;
while (j < n && a[j] == a[i]) {
freq++;
j++;
}
int right = n - left - freq;
int calls;
if (left > right)
calls = left;
else
calls = right;
if (calls < ans)
ans = calls;
left += freq;
i = j;
}
cout << ans << endl;
}
return 0;
}