fork download
  1. #include <bits/stdc++.h>
  2. #define gc getchar_unlocked
  3. #define fo(i,n) for(i=0;i<n;i++)
  4. #define Fo(i,k,n) for(i=k;i<n;i++)
  5. #define ll long long
  6. #define pii pair<int,int>
  7. #define vi vector<int>
  8. #define pb push_back
  9. #define mp make_pair
  10. #define F first
  11. #define S second
  12. using namespace std;
  13. bool f(int a, int b, int no){
  14. // cout<<no<<endl;
  15. int x, y;
  16. int six = no/6;
  17. int cut = min(2*a, 3*b)/6;
  18. x = no/2;
  19. y = no/3;
  20. int x2 = x-six;
  21. int x3 = y-six;
  22. x2 = a-x2;
  23. x3 = b-x3;
  24. if(x2<=0 && x3<=0)
  25. return true;
  26. if(x2+x3<=six)
  27. return true;
  28. return false;
  29.  
  30. }
  31. int main() {
  32. int a, b, i;
  33. cin >> a >>b;
  34. int x, y;
  35. x = 2*a, y = 3*b;
  36. i=max(x, y);
  37. while( f(a, b, i) == false ){
  38. i++;
  39. while(i%2 !=0 && i%3 !=0)
  40. i++;
  41. }
  42. cout<<i<<endl;
  43. return 0;
  44. }
Success #stdin #stdout 0s 3416KB
stdin
1083 724
stdout
2710