Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* b966 */
- /* AC (0.4s, 412KB) */
- #include <cstdio>
- #include <vector>
- #include <algorithm>
- using namespace std;
- typedef struct _line
- {
- int s, e;
- }line;
- bool cmp(line a, line b)
- {
- if(a.s == b.s) return a.e < b.e;
- return a.s < b.s;
- }
- vector<line> arr;
- int main()
- {
- for(int N; ~scanf("%d", &N) && N;)
- {
- arr.resize(N);
- int len = 0;
- for(int i = 0, s, e; i < N && scanf("%d %d", &s, &e); arr[i].s = s, arr[i].e = e, ++i);
- sort(arr.begin(), arr.end(), cmp);
- for(int i = 0; i < N; ++i)
- {
- int s = arr[i].s, e = arr[i].e;
- while(i + 1 < N && e > arr[i + 1].s)
- {
- if(e < arr[i + 1].e)
- e = arr[i + 1].e;
- ++i;
- }
- len += e - s;
- }
- printf("%d\n", len);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement