Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <vector>
- #include <queue>
- using namespace std;
- int main()
- {
- int n, l;
- cin >> n >> l;
- int x1[n], x2[n];
- for(int i = 0; i < n; i++) {
- cin >> x1[i] >> x2[i];
- }
- int L = 0;
- int R = l;
- int zalepeni = 0;
- for(int i = 0; i < n; i++) {
- int a = x1[i];
- int b = x2[i];
- 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;
- }
- }
- }
- cout << zalepeni << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement