242B - Big Segment - CodeForces Solution


implementation sortings *1100

Please click on ads to support us..

Python Code:

n=int(input())

list1=[]
list2=[]
flag=1

min,max=map(int,input().split())

for i in range(n-1):
    x,y=map(int,input().split())
    if(x<=min and y>=max):
        min=x
        max=y
        flag=i+2
    elif(x<min):
        min=x
        flag=-1
    elif(y>max):
        max=y
        flag=-1

print(flag)

C++ Code:

#include<bits/stdc++.h>
using namespace std;
#define int long long
int32_t main()
{
    int n;
    cin>>n;
   vector <pair <int,int> > v(n);
   int mx=INT_MIN;
   int mn=INT_MAX;
   for(int i=0;i<n;i++)
   {
       cin>>v[i].first>>v[i].second;
       mn=min(v[i].first,mn);
       mx=max(v[i].second,mx);
   }
   int m=0;
   for(int i=0;i<n;i++)
   {
       if(v[i].first==mn&&v[i].second==mx) {
           cout<<i+1<<endl;
           m++;
           break;
       }
   }
   if(m==0) cout<<"-1"<<endl;
}


Comments

Submit
0 Comments
More Questions

337B - Routine Problem
1392D - Omkar and Bed Wars
76E - Points
762C - Two strings
802M - April Fools' Problem (easy)
577B - Modulo Sum
1555B - Two Tables
1686A - Everything Everywhere All But One
1469B - Red and Blue
1257B - Magic Stick
18C - Stripe
1203B - Equal Rectangles
1536A - Omkar and Bad Story
1509A - Average Height
1506C - Double-ended Strings
340A - The Wall
377A - Maze
500A - New Year Transportation
908D - New Year and Arbitrary Arrangement
199A - Hexadecimal's theorem
519C - A and B and Team Training
631A - Interview
961B - Lecture Sleep
522A - Reposts
1166D - Cute Sequences
1176A - Divide it
1527A - And Then There Were K
1618E - Singers' Tour
1560B - Who's Opposite
182B - Vasya's Calendar