Advertisement
Guest User

Gym E

a guest
Jan 19th, 2012
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.30 KB | None | 0 0
  1. package com.cf;
  2.  
  3. import java.io.InputStreamReader;
  4. import java.io.PrintWriter;
  5. import java.util.Scanner;
  6.  
  7. public class ClassShedule {
  8.     public static void main(String[] args) {
  9.         solve();
  10.     }
  11.  
  12.     public static void solve() {
  13.         Scanner input = new Scanner(new InputStreamReader(System.in));
  14.         PrintWriter output = new PrintWriter(System.out);
  15.  
  16.         int Z = Integer.parseInt(input.nextLine());
  17.  
  18.         int C, T, L;
  19.  
  20.         int place, dist;
  21.  
  22.         while (Z > 0) {
  23.             int sum = 0;
  24.             int location = 0;
  25.            
  26.             String[] tmp = input.nextLine().split("\\s");
  27.             C = Integer.parseInt(tmp[0]);
  28.             T = Integer.parseInt(tmp[1]);
  29.             L = Integer.parseInt(tmp[2]);
  30.  
  31.             for (int i = 0; i < C; i++) {
  32.                 int minimal = Integer.MAX_VALUE;
  33.                 int actual = -1;
  34.                 for (int j = 0; j < T; j++) {
  35.                     String[] aux = input.nextLine().split("\\s");
  36.                     place = Integer.parseInt(aux[0]);
  37.                     dist = Integer.parseInt(aux[1]);
  38.                        
  39.                     if ((Math.abs(place - location) + dist <= minimal) || place > actual && Math.abs(place - location) + dist == minimal) {
  40.                         minimal = Math.abs(place - location) + dist;
  41.                         actual = place;
  42.                     }
  43.                 }
  44.                 sum += minimal;
  45.                 location = actual;
  46.             }
  47.             sum += Math.abs(location - L);
  48.             output.println(sum);
  49.             Z--;
  50.         }
  51.        
  52.         input.close();
  53.         output.close();
  54.         System.exit(0);
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement