Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <stdio.h>
- #include <vector>
- #include <queue>
- using namespace std;
- int main()
- {
- freopen ("output.txt","w",stdout);
- freopen ("input.txt","r",stdin);
- int Hmax;
- int numeroQuadri;
- cin >> Hmax;
- cin >> numeroQuadri;
- int quadri[numeroQuadri][2];
- for(int i = 0; i < numeroQuadri; i++)
- cin >> quadri[i][0] >> quadri[i][1];
- int i=0, j=numeroQuadri-1;
- int swaps = 0;
- while(i < j)
- {
- bool foundBiggerLeft = false;
- bool foundSmallerRight = false;
- if((quadri[i][0] < Hmax || quadri[i][1] < Hmax))
- i++;
- else
- foundBiggerLeft = true;
- if((quadri[j][0] > Hmax || quadri[j][1] > Hmax))
- j--;
- else
- foundSmallerRight = true;
- if(foundBiggerLeft && foundSmallerRight)
- {
- swaps++;
- j--;
- i++;
- }
- }
- cout << swaps;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement