fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int cmp(const void* a, const void* b) {
  5. return (*(int*)a - *(int*)b);
  6. }
  7.  
  8. int main() {
  9. int n;
  10. scanf("%d", &n);
  11.  
  12. if (n <= 0) {
  13. printf("0\n");
  14. return 0;
  15. }
  16.  
  17. int arr[1000], dep[1000];
  18.  
  19. for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  20. for (int i = 0; i < n; i++) scanf("%d", &dep[i]);
  21.  
  22. qsort(arr, n, sizeof(int), cmp);
  23. qsort(dep, n, sizeof(int), cmp);
  24.  
  25. int i = 0, j = 0;
  26. int platforms = 0, maxPlatforms = 0;
  27.  
  28. while (i < n && j < n) {
  29. if (arr[i] < dep[j]) { // STRICT < to handle equal case safely
  30. platforms++;
  31. if (platforms > maxPlatforms)
  32. maxPlatforms = platforms;
  33. i++;
  34. } else {
  35. platforms--;
  36. j++;
  37. }
  38. }
  39.  
  40. printf("%d\n", maxPlatforms);
  41. return 0;
  42. }
Success #stdin #stdout 0s 5312KB
stdin
6
900 940 950 1100 1500 1800
910 1200 1120 1130 1900 2000
stdout
3