fork download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main ()
  5. {
  6. int x, n;
  7. cin >> x >> n;
  8. int N[n][4];
  9. for (int i = 0; i < n; i++)
  10. for (int j = 0; j < 4; j++)
  11. cin >> N[i][j];
  12. for (int i = 0; i < n; i++)
  13. for (int j = 0; j < n; j++)
  14. for (int q = 0; q < 4; q++)
  15. if ((N[i][1] > N[j][1] || N[i][3] > N[j][3]) || ( (N[i][1] == N[j][1] || N[i][3] == N[j][3] ) && (N[i][0] > N[j][0] || N[i][2] > N[j][2]) ) )
  16. swap(N[i][q], N[j][q]);
  17. for (int i = 0; i < n; i++) {
  18. if (x >= N[i][0] && x <= N[i][2])
  19. N[i][1] < N[i][3] ? x = N[i][0] : x = N[i][2];
  20. for (int j = 0; j < 4; j++)
  21. N[i][j] = 0;
  22. }
  23. cout << x;
  24.  
  25. return 0;
  26. }
Success #stdin #stdout 0s 4408KB
stdin
30 4
25 35 40 30
1 32 20 30
33 22 50 29
18 10 33 19
stdout
18