fork download
  1.  
  2. #include <cstdlib>
  3. #include <iostream>
  4.  
  5. using namespace std;
  6.  
  7. const int sz = 1000000;
  8. const int maxNumber = 10000;
  9.  
  10. int arr[sz];
  11. int counting[maxNumber + 1];
  12.  
  13. void countingSort(int *arr, int l, int r) {
  14. for (int value=0; value<=maxNumber; value++) counting[value] = 0;
  15.  
  16. for (int i=l; i<=r; i++) counting[arr[i]]++;
  17.  
  18. for (int value=0; value<=maxNumber; value++) {
  19. while (counting[value]) {
  20. arr[l++] = value;
  21. counting[value]--;
  22. }
  23. }
  24. }
  25.  
  26. bool check() {
  27. for (int i=0; i<sz-1; i++){
  28. if (arr[i] > arr[i + 1]) return false;
  29. }
  30. return true;
  31. }
  32.  
  33. int main(){
  34. for (int i=0; i<sz; i++) {
  35. arr[i] = rand() % maxNumber;
  36. }
  37.  
  38. countingSort(arr, 0, sz - 1);
  39.  
  40. cout<<(check() ? "OK": "FAIL");
  41.  
  42. return 0;
  43. }
  44.  
Success #stdin #stdout 0.02s 7456KB
stdin
Standard input is empty
stdout
OK