fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5.  
  6. bool comp(int a, int b) {
  7. return a > b;
  8. }
  9.  
  10. int main() {
  11. ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  12. int n;
  13. cin >> n;
  14.  
  15. vector <int> men;
  16. vector <int> women;
  17.  
  18. for (int i = 0; i < n; i++) {
  19. bool o;
  20. int height;
  21. cin >> o >> height;
  22.  
  23. if (o == 0) {
  24. men.push_back(height);
  25. } else {
  26. women.push_back(height);
  27. }
  28. }
  29.  
  30. sort(men.begin(), men.end(), comp);
  31. sort(women.begin(), women.end(), comp);
  32.  
  33. int ans = -1;
  34.  
  35. for (int i = 0; i < max((int)men.size() - 1, 0); i++) {
  36. ans = max(ans, men[i] - men[i + 1]);
  37. }
  38.  
  39. if (men.size() > 0 && women.size() > 0) {
  40. ans = max(ans, abs(men[men.size() - 1] - women[0]));
  41. }
  42.  
  43. for (int i = 0; i < max((int)women.size() - 1, 0); i++) {
  44. ans = max(ans, women[i] - women[i + 1]);
  45. }
  46.  
  47. cout << ans;
  48.  
  49. return 0;
  50.  
  51. }
Success #stdin #stdout 0s 544KB
stdin
2
1 121
0 110
stdout
11