Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2014
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <functional>
  4.  
  5. using namespace std;
  6.  
  7. struct exam
  8. {
  9.     int starttime;
  10.     int endtime;
  11. };
  12.  
  13.  
  14. bool examcompare(exam lhs, exam rhs)
  15. {
  16.     return lhs.starttime<rhs.starttime;
  17. };
  18.  
  19.  
  20. int main()
  21. {
  22.     ios::sync_with_stdio(false);
  23.  
  24.     long int exams=0, goholes=0, comeholes=0, incounter=0, trip=0, besttrip=999999, bestgo=0, bestcome=0, counter=0, gostart=0;
  25.  
  26.     cin>>exams>>goholes>>comeholes;
  27.  
  28.     exam examarray[exams];
  29.     int gotimes[goholes], cometimes[comeholes];
  30.  
  31.     for(int counter=0; counter<exams; counter++)
  32.     {
  33.         cin>>examarray[counter].starttime;
  34.         cin>>examarray[counter].endtime;
  35.     }
  36.  
  37.     for(counter=0; counter<goholes; counter++)
  38.     {
  39.         cin>>gotimes[counter];
  40.     }
  41.  
  42.     for( counter=0; counter<comeholes; counter++)
  43.     {
  44.         cin>>cometimes[counter];
  45.     }
  46.  
  47.     sort(gotimes, gotimes+goholes);
  48.  
  49.     sort(cometimes, cometimes+comeholes);
  50.  
  51.     sort(examarray, examarray+exams, examcompare);
  52.  
  53.  
  54.     for(counter=0; counter<exams; counter++)
  55.     {
  56.         for(incounter=gostart; examarray[counter].starttime>=gotimes[incounter]; incounter++);
  57.         incounter--;
  58.         gostart=incounter;
  59.         bestgo=gotimes[incounter];
  60.  
  61.         for(incounter=0; examarray[counter].endtime>cometimes[incounter]; incounter++);
  62.         bestcome=cometimes[incounter];
  63.  
  64.         trip=(bestcome-bestgo)+1;
  65.  
  66.  
  67.         if(trip<besttrip)
  68.         {
  69.             besttrip=trip;
  70.         }
  71.  
  72.     }
  73.  
  74.  
  75.  
  76.  
  77. cout<<besttrip;
  78.  
  79.  
  80. return 0;
  81.  
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement