Advertisement
Guest User

balony

a guest
Aug 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.72 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3.  
  4. using namespace std;
  5.  
  6. int n, m, l=1, r, s;
  7. int A[1000000];
  8.  
  9. bool czy_mozliwe(int x) {
  10.     int y = m;
  11.     for (int i=0; i<n; ++i) {
  12.         y-=A[i]/x;
  13.         if(A[i]%x > 0) {
  14.             y-=1;
  15.         }
  16.     }
  17.     if (y<0) {
  18.         return false;
  19.     }
  20.     else {
  21.         return true;
  22.     }
  23. }
  24.  
  25. int main() {
  26.     cin>>n>>m;
  27.     for (int i=0; i<n; ++i) {
  28.         cin>>A[i];
  29.     }
  30.     r=*max_element(A,A+1000000);
  31.     while (true) {
  32.         s = (l+r)/2;
  33.         cin.get();
  34.         cout<<"S: "<<s<<" R: "<<r<<" L: "<<l;
  35.         if(czy_mozliwe(s) == true) {
  36.             r=s;
  37.         }
  38.         if (czy_mozliwe(s) == false) {
  39.             l=s;
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement