Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- using namespace std;
- int n, m, l=1, r, s;
- int A[1000000];
- bool czy_mozliwe(int x) {
- int y = m;
- for (int i=0; i<n; ++i) {
- y-=A[i]/x;
- if(A[i]%x > 0) {
- y-=1;
- }
- }
- if (y<0) {
- return false;
- }
- else {
- return true;
- }
- }
- int main() {
- cin>>n>>m;
- for (int i=0; i<n; ++i) {
- cin>>A[i];
- }
- r=*max_element(A,A+1000000);
- while (true) {
- s = (l+r)/2;
- cin.get();
- cout<<"S: "<<s<<" R: "<<r<<" L: "<<l;
- if(czy_mozliwe(s) == true) {
- r=s;
- }
- if (czy_mozliwe(s) == false) {
- l=s;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement