-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1783A.cpp
More file actions
39 lines (38 loc) · 880 Bytes
/
Copy path1783A.cpp
File metadata and controls
39 lines (38 loc) · 880 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
#include <iostream>
using namespace std;
#define k 101
void countingSort(int *A, int n){
int* B = new int[n];
int C[k];
fill(C, C+k, 0);
for (int i =0; i<n; i++) C[A[i]]++;
for (int i =1; i<k; i++) C[i] += C[i-1];
for (int i =0; i<n; i++){
B[C[A[i]]-1] = A[i];
C[A[i]]--;
}
for (int i = 0; i<n; i++) A[i] = B[i];
delete[] B;
}
int main(){
int t;
cin >> t;
while (t--){
int n;
cin >> n;
int *A = new int[n];
for (int i =0 ;i <n; i++){
cin >> A[i];
}
countingSort(A, n);
if (A[0] == A[n-1]){
cout<< "NO\n";
continue;
}
cout<< "YES\n";
cout << A[n-1] << " ";
for (int i = 0; i<n-1; i++) cout << A[i] << " ";
cout <<"\n";
delete[] A;
}
}