fork(1) download
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5. // your code goes here
  6. int arr[5]={35,40,60,80,50};
  7. int start=80,end=265;
  8. cout<<"Enter the number of students/n";
  9. int k,ans;
  10. cin>>k;
  11. while(start<=end){
  12. int mid= start+(end-start)/2;
  13.  
  14. int pages=0,count=1;
  15. for(int i=0;i<5;i++){
  16. pages+=arr[i];
  17. if(pages> mid){
  18. count++;
  19. pages=arr[0];
  20. }
  21. }
  22.  
  23. if(count<=k){
  24. ans=mid;
  25. end=mid-1;
  26. }else{
  27. start=mid+1;
  28. }
  29. }
  30. cout<<ans;
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5324KB
stdin
3
stdout
Enter the number of students/n85