Advertisement
Guest User

Untitled

a guest
Oct 19th, 2019
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /*
  2. ID: aadithyaa1
  3. LANG: JAVA
  4. TASK: marathon
  5. */
  6. import java.io.File;
  7. import java.io.IOException;
  8. import java.io.PrintWriter;
  9. import java.util.Scanner;
  10. import java.util.*;
  11.  
  12. class marathon {
  13. public int distance(int x, int y) {
  14. return Math.abs(x-y);
  15. }
  16. public static void main(String[] args) throws IOException {
  17. Scanner sc = new Scanner(new File("marathon.in"));
  18. PrintWriter pw = new PrintWriter(new File("marathon.out"));
  19. int N = sc.nextInt();
  20. ArrayList<ArrayList> checkpoints = new ArrayList<>();
  21.  
  22. for(int i = 1; i <= 2*N; i++) {
  23. ArrayList<Integer> checkpair = new ArrayList<>();
  24. checkpair.add(sc.nextInt());
  25. checkpair.add(sc.nextInt());
  26. checkpoints.add(checkpair);
  27. }
  28. int max = 0;
  29. int total = 0;
  30. for(int i = 0; i < N; i++) {
  31. total += distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1));
  32. if(distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1)) >temp) {
  33. max = distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1));
  34. }
  35. }
  36. pw.println(total - max);
  37. pw.close();
  38.  
  39.  
  40.  
  41. }
  42.  
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement