编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#3098 | #1004. 提瓦特大冒险 | Compile Error | 0 | 0 ms | 0 K | Java / 1.5 K | Met | 2023-11-23 3:12:06 |
import java.util.HashMap;
import java.util.Scanner;
public class Explorer {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int N = scanner.nextInt();
int M = scanner.nextInt();
int T = scanner.nextInt();
int[] A = new int[N - 1];
for (int i = 0; i < N - 1; i++) {
A[i] = scanner.nextInt();
}
HashMap<Integer, Integer> rewards = new HashMap<>();
for (int i = 0; i < M; i++) {
int Xi = scanner.nextInt();
int Yi = scanner.nextInt();
rewards.put(Xi, Yi);
}
boolean canReach = canReachLastRoom(N, T, A, rewards);
if (canReach) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
private static boolean canReachLastRoom(
int N, int timeLimit, int[] travelTimes, HashMap<Integer, Integer> rewardRooms) {
int currentTime = timeLimit;
for (int i = 0; i < N - 1; i++) {
// Move to the next room
currentTime -= travelTimes[i];
// Check if there is a reward in the current room
if (rewardRooms.containsKey(i + 2)) {
currentTime += rewardRooms.get(i + 2);
}
// If the remaining time is not enough to reach the next room, return false
if (currentTime <= 0) {
return false;
}
}
return true;
}
}
编译信息
A TimeLimitExceeded encountered while compiling your code.