Advertisement
MegaVerkruzo

ыва

Sep 9th, 2019
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int a, b, c, k;
  7. int count = 0;
  8. cin >> a >> b >> c >> k;
  9. while (a > 0 || b > 0 || c > 0) {
  10. int buf = k;
  11. while (buf - 3 >= 0 && c > 0) {
  12. c--;
  13. buf -= 3;
  14. }
  15. while (buf - 2 >= 0 && b > 0) {
  16. b--;
  17. buf -= 2;
  18. }
  19. while (buf - 1 >= 0 && a > 0) {
  20. a--;
  21. buf -= 1;
  22. }
  23. if (buf == 0) {
  24. count++;
  25. } else {
  26. while (b > 0 && buf > 0) {
  27. b--;
  28. buf -= 2;
  29. }
  30. if (buf <= 0) {
  31. count++;
  32. } else {
  33. while (c > 0 && buf > 0) {
  34. c--;
  35. buf -= 3;
  36. }
  37. if (buf <= 0) {
  38. count++;
  39. }
  40. }
  41. }
  42. }
  43. cout << count;
  44. return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement