Advertisement
Guest User

v1.1

a guest
Oct 13th, 2022
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class MineralWater {
  4.  
  5. public static void main(String[] args) {
  6.  
  7. Scanner scanner = new Scanner(System.in);
  8. int small = Integer.parseInt(scanner.nextLine()); //4
  9. int big = Integer.parseInt(scanner.nextLine()); //0
  10. int capacity = Integer.parseInt(scanner.nextLine()); //11
  11.  
  12. int result = capacity - (big * 5 + small); // 11 - (10 + 4) = -3
  13.  
  14. if (result <= 0) {
  15. if( result == 0) {
  16. System.out.print(small); // all loaded
  17. } else if (capacity < (big *5) || capacity < small ){
  18. System.out.println(-1);
  19. }
  20. else {
  21. System.out.println(small + result); //small (4) + result (-3) = 1
  22. }
  23. } else {
  24. System.out.println(-1); // not enough bottles for the load
  25. }
  26.  
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement