fork download
  1.  
  2. #include <bits/stdc++.h>
  3. using namespace std;
  4. using ll = long long int;
  5. bool fun(ll mid, int k, vector<int>&v){
  6. int count=0;
  7. while(count<mid){
  8. sort(v.begin(),v.end(),greater<int>());
  9. for(int i=0;i<k;i++)
  10. {
  11. if(v[i]==0){
  12. return false;
  13. }
  14. else{
  15. v[i]--;
  16. }
  17. }
  18. count++;
  19. }
  20. return true;
  21. }
  22. int main()
  23. {
  24. vector<int>v1={3,3,3};
  25.  
  26. int n=v1.size();
  27. int k=2;
  28.  
  29. int l=0;
  30. ll h=n*(*max_element(v1.begin(),v1.end()));
  31. ll ans=0;
  32. while(l<=h){
  33. ll mid=l+(h-l)/2;
  34. vector<int>v=v1;
  35. if(fun(mid,k,v)){
  36. ans=mid;
  37. l=mid+1;
  38. }
  39. else{
  40. h=mid-1;
  41. }
  42. }
  43. cout<<ans<<endl;
  44. return 0;
  45. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
4