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. if(k>5){
  15. cout<<"yai nhi ho skta :"<<-1;
  16. return 0;
  17. }
  18. int pages=0,count=1;
  19. for(int i=0;i<5;i++){
  20. pages+=arr[i];
  21. if(pages> mid){
  22. count++;
  23. pages=arr[i];
  24. }
  25. }
  26.  
  27. if(count<=k){
  28. ans=mid;
  29. end=mid-1;
  30. }else{
  31. start=mid+1;
  32. }
  33. }
  34. cout<<ans;
  35. return 0;
  36. }
Success #stdin #stdout 0s 5320KB
stdin
2
stdout
Enter the number of students/n135