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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
| import java.util.Scanner;
public class question2 {
public static void main(String[] args) { Scanner in = new Scanner(System.in); int M, D; int T; M = in.nextInt(); D = in.nextInt(); T = in.nextInt(); int len = 0; len = judgeDistance(M, T, 0, D)[0]; int tt = judgeDistance(M, T, 0, D)[1]; if (len >= D) { System.out.print("YES "); System.out.println(T-tt); } else { System.out.print("NO "); System.out.println(len); }
}
static int[] judgeDistance(int M, int T, int dis, int D) { int[] res = new int[2]; if (T == 0) { res[0] = dis; res[1] = T; return res; } if (dis >= D && T >= 0) { res[0] = dis; res[1] = T; return res; } int minT = 0;
if (M >= 10) { int d1 = judgeDistance(M - 10, T - 1, dis + 60, D)[0]; int t1 = judgeDistance(M - 10, T - 1, dis + 60, D)[1]; int d2 = judgeDistance(M + 4, T - 1, dis, D)[0]; int t2 = judgeDistance(M + 4, T - 1, dis, D)[1]; int d3 = judgeDistance(M, T - 1, dis + 17, D)[0]; int t3 = judgeDistance(M, T - 1, dis + 17, D)[1]; minT = Math.max(t1, Math.max(t2, t3)); dis = Math.max(d1, Math.max(d2, d3));
} else { int d2 = judgeDistance(M + 4, T - 1, dis, D)[0]; int t2 = judgeDistance(M + 4, T - 1, dis, D)[1]; int d3 = judgeDistance(M, T - 1, dis + 17, D)[0]; int t3 = judgeDistance(M, T - 1, dis + 17, D)[1]; minT = Math.max(t2,t3); dis = Math.max(d2, d3); } res[0] = dis; res[1] = minT; return res; } }
|