Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.*;
- public class stacking {
- public static void main(String[] args) throws Exception {
- Scanner in = new Scanner(new File("stacking.in"));
- int StackCount = in.nextInt();
- int InstructionCount = in.nextInt();
- int[] stacks = new int[StackCount];
- for (int i = 0; i < InstructionCount; i ++) { // haybales count from 0
- int from = in.nextInt() - 1; // -1 for array referencing
- int to = in.nextInt() - 1; // -1 for array referencing
- //add 1 haybale from arrays 'from' to 'to'
- for (int j = from; j <= to; j ++) { //adding 1
- stacks[j] ++;
- }
- }
- int result = 0;
- /* for (int a = 0; a <stacks.length; a ++) { //checking if numbers are sorted correctly
- System.out.println(stacks[a]);
- }
- */
- //sort the values in ascending order
- Arrays.sort(stacks);
- int index = StackCount/2;
- result = stacks[index];
- PrintWriter out = new PrintWriter(new File("stacking.out"));
- System.out.println(result);
- out.println(result);
- in.close();
- out.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement