Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <functional>
- using namespace std;
- struct exam
- {
- int starttime;
- int endtime;
- };
- bool examcompare(exam lhs, exam rhs)
- {
- return lhs.starttime<rhs.starttime;
- };
- int main()
- {
- ios::sync_with_stdio(false);
- long int exams=0, goholes=0, comeholes=0, incounter=0, trip=0, besttrip=999999, bestgo=0, bestcome=0, counter=0, gostart=0;
- cin>>exams>>goholes>>comeholes;
- exam examarray[exams];
- int gotimes[goholes], cometimes[comeholes];
- for(int counter=0; counter<exams; counter++)
- {
- cin>>examarray[counter].starttime;
- cin>>examarray[counter].endtime;
- }
- for(counter=0; counter<goholes; counter++)
- {
- cin>>gotimes[counter];
- }
- for( counter=0; counter<comeholes; counter++)
- {
- cin>>cometimes[counter];
- }
- sort(gotimes, gotimes+goholes);
- sort(cometimes, cometimes+comeholes);
- sort(examarray, examarray+exams, examcompare);
- for(counter=0; counter<exams; counter++)
- {
- for(incounter=gostart; examarray[counter].starttime>=gotimes[incounter]; incounter++);
- incounter--;
- gostart=incounter;
- bestgo=gotimes[incounter];
- for(incounter=0; examarray[counter].endtime>cometimes[incounter]; incounter++);
- bestcome=cometimes[incounter];
- trip=(bestcome-bestgo)+1;
- if(trip<besttrip)
- {
- besttrip=trip;
- }
- }
- cout<<besttrip;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement