I’m currently trying to solve Haybale Stacking. You can find this problem in Silver -> prefix sum -> last problem on the first list of problems. It directs me to Sphere Online Judge. I was wondering if you submit your code with terminal or with a file.
This is my code so far.
import java.util.Arrays;
import java.util.Scanner;
public class Haybale_Stacking {
public static void main(String[] args) {
Scanner sc1 = new Scanner(System.in);
int stacks = sc1.nextInt();
int instructions = sc1.nextInt();
int start = 0;
int end = 0;
int[] bales = new int[stacks];
for(int x = 0; x < instructions;x++) {
sc1.nextLine();
start = sc1.nextInt();
end = sc1.nextInt();
for(int y = start; y <= end;y++) {
bales[y-1] ++;
}
}
Arrays.sort(bales);
System.out.println(bales[stacks/2]);
}
tried System.in and got compilation error… Everything works in Eclipes… Also what would the file name be. Heres the link, https://www.spoj.com/problems/HAYBALE/