Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <queue>
- #include <algorithm>
- using namespace std;
- int main()
- {
- int n, l;
- cin >> n >> l;
- pair<int, int> p[n];
- for(int i = 0; i < n; i++) {
- cin >> p[i].second >> p[i].first;
- }
- int L = 0;
- int R = l;
- int zalepeni = 0;
- for(int i = 0; i < n; i++) {
- int a = p[i].second;
- int b = p[i].first;
- if(R < a) {
- continue;
- }
- if(b < L) {
- continue;
- }
- if(a < L and R < b) {
- continue;
- }
- if(L <= a and b <= R) {
- zalepeni += 1;
- continue;
- }
- if(a < L) {
- int strci = L - a;
- if(strci < 0) {
- strci *= -1; // dolzinata mora da e pozitiven broj
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- L = a;
- zalepeni += 1;
- }
- }
- else if(R < b) {
- int strci = b - R;
- if(strci < 0) {
- strci *= -1;
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- R = b;
- zalepeni += 1;
- }
- }
- }
- int zalepeni2 = 0;
- sort(p, p + n);
- for(int i = n - 1; i >= 0; i--) {
- int a = p[i].second;
- int b = p[i].first;
- if(R < a) {
- continue;
- }
- if(b < L) {
- continue;
- }
- if(a < L and R < b) {
- continue;
- }
- if(L <= a and b <= R) {
- zalepeni2 += 1;
- continue;
- }
- if(a < L) {
- int strci = L - a;
- if(strci < 0) {
- strci *= -1; // dolzinata mora da e pozitiven broj
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- L = a;
- zalepeni2 += 1;
- }
- }
- else if(R < b) {
- int strci = b - R;
- if(strci < 0) {
- strci *= -1;
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- R = b;
- zalepeni2 += 1;
- }
- }
- }
- int zalepeni3 = 0;
- for(int i = 0; i < n; i++) {
- int a = p[i].second;
- int b = p[i].first;
- if(R < a) {
- continue;
- }
- if(b < L) {
- continue;
- }
- if(a < L and R < b) {
- continue;
- }
- if(L <= a and b <= R) {
- zalepeni3 += 1;
- continue;
- }
- if(a < L) {
- int strci = L - a;
- if(strci < 0) {
- strci *= -1; // dolzinata mora da e pozitiven broj
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- L = a;
- zalepeni3 += 1;
- }
- }
- else if(R < b) {
- int strci = b - R;
- if(strci < 0) {
- strci *= -1;
- }
- int dolzina = b - a;
- if(dolzina < 0) {
- dolzina *= -1;
- }
- if(strci <= dolzina / 2) {
- R = b;
- zalepeni3 += 1;
- }
- }
- }
- cout << max(max(zalepeni, zalepeni2), zalepeni3) << endl;
- return 0;
- }
- /*
- 7 5
- 2 4
- -3 3
- 7 10
- 1 8
- 6 7
- 6 7
- -1 6
- 2 4
- -3 3
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement