-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCount_and_Sort.cpp
More file actions
43 lines (41 loc) · 791 Bytes
/
Copy pathCount_and_Sort.cpp
File metadata and controls
43 lines (41 loc) · 791 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
43
#include <iostream>
#include <cstring>
using namespace std;
int A[1000001], B[1000001], C[1000001];
void countSort(int n, int mn, int mx)
{
memset(C, 0, (n + 1) * sizeof(int));
for (int i = 1; i <= n; i++)
{
C[A[i] - mn + 1]++;
}
for (int i = 1; i <= mx; i++)
{
C[i] = C[i] + C[i - 1];
}
for (int i = n; i > 0; i--)
{
B[C[A[i] - mn + 1]] = A[i];
C[A[i] - mn + 1]--;
}
}
int main()
{
int n, t, mn, mx;
cin >> t;
while (t--)
{
cin >> n >> mn >> mx;
for (int i = 1; i <= n; i++)
{
cin >> A[i];
}
countSort(n, mn, mx);
for (int i = 1; i <= n; i++)
{
cout << B[i] << " ";
}
cout << endl;
}
return 0;
}