-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSurvive.java
More file actions
29 lines (25 loc) · 789 Bytes
/
Survive.java
File metadata and controls
29 lines (25 loc) · 789 Bytes
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
package Greedy;
import java.util.Scanner;
/**
* Given the number of days S to survive on an island.
* You can buy food on all days except sunday.
* You are also given the food units consumed by you each day as M.
* Also the max food you can buy on every day is N.
*/
public class Survive {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Enter S, N, M: ");
int S = sc.nextInt();
int N = sc.nextInt();
int M = sc.nextInt();
int totalFood = S * M;
int result;
if (M > N || (S >= 6 && (7 * M) > (6 * N))) {
result = -1;
} else {
result = (int) Math.ceil((double) totalFood / N);
}
System.out.println(result);
}
}