Вот мой код:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(solution(sc.nextInt(), sc.nextInt()));
}
public static int solution(int totalMin, int chores) {
Scanner sc = new Scanner(System.in);
int[] choresTime = new int[chores];
int choresDone = 0;
for (int i = 0; i < chores; i++) {
choresTime[i] = sc.nextInt();
}
// Sorting the Array's Values from Least to Greatest
Arrays.sort(choresTime);
for (int i = 0; i < choresTime.length; i++) {
if (totalMin - choresTime[i] < 0) {
break;
} else {
totalMin -= choresTime[i];
choresDone++;
}
}
return choresDone;
}
}
Несмотря на то, что этот код прекрасно работает на IntelliJ, я получаю NoSuchElementException, когда проверяю свой ответ на DMOJ.
Результаты выполнения на DMOJ:
Контрольный пример № 1: IR (java.util.NoSuchElementException) [0,627 с, 39,98 МБ] (0/10)
Тестовый пример № 2: IR (java.util.NoSuchElementException) [0,546 с, 39,15 МБ] (0/10)
Тестовый пример № 3: IR (java.util.NoSuchElementException) [0,466с, 39,70 МБ] (0/10)
Контрольный пример № 4: IR (java.util.NoSuchElementException) [0,445 с, 39,64 МБ] (0/10)
Контрольный пример #5: IR (java.util.NoSuchElementException) [0,421 с, 39,55 МБ] (0/10)
Кто-нибудь знает почему?