Created
November 24, 2016 20:04
-
-
Save KhaledElshamy/035ba0c28ab3906b8128bf111a5c70ff to your computer and use it in GitHub Desktop.
Milking Cows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <bits/stdc++.h> | |
| using namespace std; | |
| int main() | |
| { | |
| int num,start,end,max=0,gap=0; | |
| cin>>num; | |
| pair<int,int>x[5000]; | |
| for(int i=0;i<num;i++) | |
| cin>>x[i].first>>x[i].second; | |
| sort(x,x+num); | |
| start=x[0].first,end=x[0].second; | |
| for(int i=1;i<num;i++) | |
| { | |
| if(x[i].first<end) | |
| end=(x[i].second<end?end:x[i].second); | |
| else | |
| { | |
| max=(end-start>max)?end-start:max; | |
| gap=(x[i].first-end>gap)?x[i].first-end:gap; | |
| start=x[i].first,end=x[i].second; | |
| } | |
| max=(end-start>max)?end-start:max; | |
| } | |
| cout<<max<<' '<<gap<<endl; | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment