Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <utility>
- #include <string>
- #include <math.h>
- #include <map>
- #include <set>
- #include <queue>
- using namespace std;
- typedef long long ll;
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(0);
- int n;
- cin >> n;
- int ind = 0;
- vector <pair<int, bool>> a(n * 2);
- for (int i = 0; i < n; i++) {
- int x, y;
- cin >> x >> y;
- a[ind++] = { x, true };
- a[ind++] = { y, false };
- }
- sort(a.begin(), a.end());
- int ans = 0;
- int count = 1;
- for (int i = 1; i < a.size(); i++) {
- if (count >= 1)
- ans += a[i].first - a[i - 1].first;
- if (a[i].second == true)
- count++;
- else
- count--;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement