Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.cf;
- import java.io.InputStreamReader;
- import java.io.PrintWriter;
- import java.util.Scanner;
- public class ClassShedule {
- public static void main(String[] args) {
- solve();
- }
- public static void solve() {
- Scanner input = new Scanner(new InputStreamReader(System.in));
- PrintWriter output = new PrintWriter(System.out);
- int Z = Integer.parseInt(input.nextLine());
- int C, T, L;
- int place, dist;
- while (Z > 0) {
- int sum = 0;
- int location = 0;
- String[] tmp = input.nextLine().split("\\s");
- C = Integer.parseInt(tmp[0]);
- T = Integer.parseInt(tmp[1]);
- L = Integer.parseInt(tmp[2]);
- for (int i = 0; i < C; i++) {
- int minimal = Integer.MAX_VALUE;
- int actual = -1;
- for (int j = 0; j < T; j++) {
- String[] aux = input.nextLine().split("\\s");
- place = Integer.parseInt(aux[0]);
- dist = Integer.parseInt(aux[1]);
- if ((Math.abs(place - location) + dist <= minimal) || place > actual && Math.abs(place - location) + dist == minimal) {
- minimal = Math.abs(place - location) + dist;
- actual = place;
- }
- }
- sum += minimal;
- location = actual;
- }
- sum += Math.abs(location - L);
- output.println(sum);
- Z--;
- }
- input.close();
- output.close();
- System.exit(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement