Advertisement
Guest User

Untitled

a guest
Oct 21st, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1.  
  2. import java.util.*;
  3. import java.io.*;
  4.  
  5. public class stacking {
  6. public static void main(String[] args) throws Exception {
  7. Scanner in = new Scanner(new File("stacking.in"));
  8.  
  9. int StackCount = in.nextInt();
  10. int InstructionCount = in.nextInt();
  11.  
  12. int[] stacks = new int[StackCount];
  13. for (int i = 0; i < InstructionCount; i ++) { // haybales count from 0
  14. int from = in.nextInt() - 1; // -1 for array referencing
  15. int to = in.nextInt() - 1; // -1 for array referencing
  16. //add 1 haybale from arrays 'from' to 'to'
  17.  
  18. for (int j = from; j <= to; j ++) { //adding 1
  19. stacks[j] ++;
  20. }
  21. }
  22.  
  23. int result = 0;
  24.  
  25. /* for (int a = 0; a <stacks.length; a ++) { //checking if numbers are sorted correctly
  26. System.out.println(stacks[a]);
  27. }
  28. */
  29.  
  30. //sort the values in ascending order
  31.  
  32. Arrays.sort(stacks);
  33.  
  34. int index = StackCount/2;
  35.  
  36. result = stacks[index];
  37.  
  38. PrintWriter out = new PrintWriter(new File("stacking.out"));
  39. System.out.println(result);
  40. out.println(result);
  41. in.close();
  42. out.close();
  43. }
  44.  
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement