Advertisement
Guest User

Untitled

a guest
Jul 4th, 2017
177
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <stdio.h>
  4. #include <vector>
  5. #include <queue>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10.  
  11.  
  12. freopen ("output.txt","w",stdout);
  13. freopen ("input.txt","r",stdin);
  14.  
  15.  
  16. int Hmax;
  17. int numeroQuadri;
  18. cin >> Hmax;
  19. cin >> numeroQuadri;
  20.  
  21. int quadri[numeroQuadri][2];
  22.  
  23. for(int i = 0; i < numeroQuadri; i++)
  24. cin >> quadri[i][0] >> quadri[i][1];
  25.  
  26. int i=0, j=numeroQuadri-1;
  27.  
  28. int swaps = 0;
  29.  
  30. while(i < j)
  31. {
  32. bool foundBiggerLeft = false;
  33. bool foundSmallerRight = false;
  34.  
  35. if((quadri[i][0] < Hmax || quadri[i][1] < Hmax))
  36. i++;
  37. else
  38. foundBiggerLeft = true;
  39.  
  40.  
  41. if((quadri[j][0] > Hmax || quadri[j][1] > Hmax))
  42. j--;
  43. else
  44. foundSmallerRight = true;
  45.  
  46.  
  47. if(foundBiggerLeft && foundSmallerRight)
  48. {
  49.  
  50. swaps++;
  51. j--;
  52. i++;
  53.  
  54. }
  55.  
  56. }
  57.  
  58. cout << swaps;
  59.  
  60. return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement