Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ID: aadithyaa1
- LANG: JAVA
- TASK: marathon
- */
- import java.io.File;
- import java.io.IOException;
- import java.io.PrintWriter;
- import java.util.Scanner;
- import java.util.*;
- class marathon {
- public int distance(int x, int y) {
- return Math.abs(x-y);
- }
- public static void main(String[] args) throws IOException {
- Scanner sc = new Scanner(new File("marathon.in"));
- PrintWriter pw = new PrintWriter(new File("marathon.out"));
- int N = sc.nextInt();
- ArrayList<ArrayList> checkpoints = new ArrayList<>();
- for(int i = 1; i <= 2*N; i++) {
- ArrayList<Integer> checkpair = new ArrayList<>();
- checkpair.add(sc.nextInt());
- checkpair.add(sc.nextInt());
- checkpoints.add(checkpair);
- }
- int max = 0;
- int total = 0;
- for(int i = 0; i < N; i++) {
- total += distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1));
- if(distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1)) >temp) {
- max = distance(checkpoints.get(i).get(0),checkpoints.get(i).get(1));
- }
- }
- pw.println(total - max);
- pw.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement