-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaliceApple.java
30 lines (27 loc) · 1009 Bytes
/
aliceApple.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class aliceApple {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter the number of red apples needed: ");
int M = in.nextInt();
System.out.print("Enter the number of apples per tree: ");
int K = in.nextInt();
System.out.print("Enter the number of trees in north: ");
@SuppressWarnings("unused")
int N = in.nextInt();
System.out.print("Enter the number of trees in east: ");
int E = in.nextInt();
System.out.print("Enter the number of trees in south: ");
int S = in.nextInt();
System.out.print("Enter the number of trees in west: ");
int W = in.nextInt();
if (M <= S * K) {
System.out.println(M);
} else if (M <= S * K + W + E) {
System.out.println(S * K + (M - S * K) * K);
} else {
System.out.println(-1);
}
in.close();
}
}