Advertisement
Guest User

Untitled

a guest
Mar 6th, 2015
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.91 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. #define NMax 105
  6.  
  7. ifstream f("lapte.in");
  8. ofstream g("lapte.out");
  9.  
  10. int n,L;
  11.  
  12. struct pct
  13. {
  14.     int A,B,id;
  15.  
  16.     bool operator < (const pct &t) const
  17.     {
  18.         if(A-B < t.A-t.B) return true;
  19.         return false;
  20.     }
  21. } v[NMax];
  22.  
  23. struct pct2
  24. {
  25.     int A,B,id;
  26.  
  27.     bool operator < (const pct2 &t) const
  28.     {
  29.         if(id < t.id) return true;
  30.         return false;
  31.     }
  32. } sol[NMax];
  33.  
  34. bool verif(int T)
  35. {
  36.     int A = 0, B = 0, time;
  37.  
  38.     for(int i=1;i<=n;++i)
  39.     {
  40.         if(A < L)
  41.         {
  42.             time = T / v[i].A;
  43.  
  44.             if(A + time < L)
  45.             {
  46.                 A += time;
  47.                 sol[i].A = time;
  48.                 sol[i].B = 0;
  49.             }
  50.             else
  51.             {
  52.                 sol[i].A = L-A;
  53.  
  54.                 time = time - (L-A);
  55.                 time = time * v[i].A / v[i].B;
  56.                 A = L;
  57.                 B += time;
  58.  
  59.                 sol[i].B = time;
  60.             }
  61.         }
  62.         else
  63.         {
  64.             time = T / v[i].B;
  65.             B += time;
  66.             sol[i].B = time;
  67.             sol[i].A = 0;
  68.         }
  69.     }
  70.  
  71.     if(A >= L && B >= L) return true;
  72.     return false;
  73. }
  74.  
  75. int rez = 100;
  76.  
  77. int main()
  78. {
  79.     int i;
  80.  
  81.     f>>n>>L;
  82.  
  83.     for(i=1;i<=n;++i)
  84.     {
  85.         f>>v[i].A>>v[i].B;
  86.         v[i].id = i;
  87.     }
  88.  
  89.     sort(v+1,v+n+1);
  90.  
  91.     int st,dr,mij;
  92.     st = 1, dr = 100;
  93.     while(st <= dr)
  94.     {
  95.         mij = (st+dr)/2;
  96.  
  97.         if(verif(mij))
  98.         {
  99.             if(mij < rez) rez = mij;
  100.             dr = mij - 1;
  101.         }
  102.         else
  103.         {
  104.             st = mij + 1;
  105.         }
  106.     }
  107.  
  108.     verif(rez);
  109.  
  110.     for(i=1;i<=n;++i) sol[i].id = v[i].id;
  111.  
  112.     sort(sol+1,sol+n+1);
  113.  
  114.     g<<rez<<"\n";
  115.     for(i=1;i<=n;++i) g<<sol[i].A<<" "<<sol[i].B<<"\n";
  116.  
  117.     f.close();
  118.     g.close();
  119.     return 0;
  120. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement