<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      Codeforces Round #602 (Div. 2, based on Technocup 2020 Elimination Round 3) A. Math Problem 水題

      A. Math Problem

      Your math teacher gave you the following problem:

      There are n segments on the x-axis, [l1;r1],[l2;r2],…,[ln;rn]. The segment [l;r] includes the bounds, i.e. it is a set of such x that l≤x≤r. The length of the segment [l;r] is equal to r?l.

      Two segments [a;b] and [c;d] have a common point (intersect) if there exists x that a≤x≤b and c≤x≤d. For example, [2;5] and [3;10] have a common point, but [5;6] and [1;4] don't have.

      You should add one segment, which has at least one common point with each of the given segments and as short as possible (i.e. has minimal length). The required segment can degenerate to be a point (i.e a segment with length zero). The added segment may or may not be among the given n segments.

      In other words, you need to find a segment [a;b], such that [a;b] and every [li;ri] have a common point for each i, and b?a is minimal.

      Input

      The first line contains integer number t (1≤t≤100) — the number of test cases in the input. Then t test cases follow.

      The first line of each test case contains one integer n (1≤n≤105) — the number of segments. The following n lines contain segment descriptions: the i-th of them contains two integers li,ri (1≤li≤ri≤109).

      The sum of all values n over all the test cases in the input doesn't exceed 105.

      Output

      For each test case, output one integer — the smallest possible length of the segment which has at least one common point with all given segments.

      Example

      input
      4
      3
      4 5
      5 9
      7 7
      5
      11 19
      4 17
      16 16
      3 12
      14 17
      1
      1 10
      1
      1 1
      output
      2
      4
      0
      0

      Note

      In the first test case of the example, we can choose the segment [5;7] as the answer. It is the shortest segment that has at least one common point with all given segments.

      題意

      給你若干個區間,然后你需要找到一個長度最小的區間,覆蓋住所有的區間,問你這個區間最小是多少

      題解

      我們考慮l最大能夠是多少,r最小能夠是多少,然后我們就發現 l = min(a[i].r,l),r = max(a[i].l,r),然后最后取個差值就好

      代碼

      #include<bits/stdc++.h>
      using namespace std;
      
      vector<pair<int,int> >A;
      void solve(){
      	int n;cin>>n;
      	A.clear();
      	for(int i=0;i<n;i++){
      		int x,y;
      		cin>>x>>y;
      		A.push_back(make_pair(x,y));
      	}
      	sort(A.begin(),A.end());
      	int ll = A[0].first,lr=A[0].second;
      	int rl = A[0].first,rr=A[0].second;
      	for(int i=0;i<n;i++){
      		lr = min(lr,A[i].second);
      		rl = max(rl,A[i].first);
      	}
         // cout<<lr<<" "<<rl<<endl;
      	if(lr>=rl){
      		cout<<"0"<<endl;
      	}else{
      		cout<<rl-lr<<endl;
      	}
      }
      int main(){
      	int t;
      	scanf("%d",&t);
      	while(t--){
      		solve();
      	}
      }
      
      posted @ 2019-11-24 22:59  qscqesze  閱讀(365)  評論(0)    收藏  舉報
      主站蜘蛛池模板: 亚洲天堂一区二区三区四区| 国产精品一区在线蜜臀| 综合区一区二区三区狠狠| 亚洲av日韩av综合在线观看| 欧美丰满熟妇xxxx性ppx人交| 国产成人精彩在线视频| 精品无码久久久久国产电影| 国产最新进精品视频| 阜新| 国产精品男女爽免费视频| 亚洲一区二区三区av激情| 人妻av一区二区三区av免费 | 日韩精品国产二区三区| 在线涩涩免费观看国产精品| 久久久久久久久久久免费精品 | 日韩中文字幕精品人妻| 亚洲永久一区二区三区在线| 亚洲AV旡码高清在线观看| 巴青县| 亚洲乱色一区二区三区丝袜| 亚洲国产欧美一区二区好看电影| 亚洲精品~无码抽插| 好看的国产精品自拍视频| 日本亚洲一区二区精品| 在线 | 国产精品99传媒a| 国产黄色一区二区三区四区| 亚洲欧洲一区二区精品| 国产高清一区二区三区视频 | 欧美肥老太牲交大战| 梁河县| 亚洲熟妇自偷自拍另欧美| 亚洲成人av综合一区| 仁寿县| 无码av永久免费专区麻豆| 国产精品SM捆绑调教视频| 久久精品国产www456c0m| 亚洲国产成人极品综合| 国产激情一区二区三区不卡| 好紧好滑好湿好爽免费视频| 国产精品538一区二区在线| 精品国产污污免费网站入口|