Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.89 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long n,m,wynik,zly,dobry,czas,L,P,S,b;
  5. long long t[1000006],maszyny;
  6.  
  7. int main()
  8. {
  9.     ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
  10.  
  11.     cin>>n>>m;
  12.  
  13.     for(int i = 1; i <= n; i++)
  14.     {
  15.         cin>>t[i];
  16.         dobry = max(dobry,t[i]);
  17.         zly += t[i];
  18.     }
  19.  
  20.     L = dobry;
  21.     P = zly;
  22.  
  23.     while(L != P)
  24.     {
  25.         czas = 0;
  26.         S = (L+P) / 2;
  27.         b = S;
  28.         for(int j = 1; j <= n; j++)
  29.         {
  30.             czas = max(maszyny,czas);
  31.             if(maszyny < S)
  32.             {
  33.                 maszyny += t[j];
  34.             }
  35.             else
  36.             {
  37.                 maszyny = 0;
  38.                 maszyny += t[j];
  39.             }
  40.  
  41.         }
  42.         //cout<<czas<<maszyny<<endl;
  43.         if(czas > S)
  44.             L = S+1;
  45.         else
  46.             P = S;
  47.     }
  48.     cout<<L;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement