|
- #include <algorithm>
- #include <iostream>
- #include <cmath>
- #include <cstring>
- #include <map>
- #include <string>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cstdio>
- #include <cstdlib>
- using namespace std;
- struct bla
- {
- int q,z;
- }a[21000];
- int n,all=0;
- bool cmp(bla x,bla y)
- {
- return x.q<y.q;
- }
- int main()
- {
- scanf("%d",&n);
- for(int i=1;i<=n;i++)
- scanf("%d%d",&a[i].q,&a[i].z);
- sort(a+1,a+1+n,cmp);
- int qi=a[1].q,zh=a[1].z;
- for(int i=2;i<=n;i++)
- {
- if(a[i].q>zh)
- all+=zh-qi,qi=a[i].q,zh=a[i].z;
- else
- zh=max(zh,a[i].z);
- }
- printf("%d",all+zh-qi);
- return 0;
- }
复制代码 |
|