My issue
Exception in thread “main” java.util.NoSuchElementException
at java.base/java.util.Scanner.throwFor(Scanner.java:937)
at java.base/java.util.Scanner.next(Scanner.java:1594)
at java.base/java.util.Scanner.nextInt(Scanner.java:2258)
at java.base/java.util.Scanner.nextInt(Scanner.java:2212)
at Main.main(Main.java:7)
why is this eating my brain… and i also tried to copy paste submitted solution from all submissions still i am getting the same error
My code
import java.util.Arrays;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N= sc.nextInt();
long[] budgets = new long[N];
for (int i = 0; i < N; i++) {
budgets[i] = sc.nextLong();
}
long maxRevenue = findMaxRevenue(budgets);
System.out.println(maxRevenue);
}
public static long findMaxRevenue(long[] budgets) {
int n = budgets.length;
Arrays.sort(budgets);
long maxRevenue = 0;
for (int i = 0; i < n; i++) {
long revenue = budgets[i] * (n - i);
if (revenue > maxRevenue) {
maxRevenue = revenue;
}
}
return maxRevenue;
}
}
Problem Link: CodeChef: Practical coding for everyone