Advertisement
Guest User

Untitled

a guest
Jul 10th, 2016
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.37 KB | None | 0 0
  1. //package com.kattis;
  2.  
  3. import javax.annotation.Generated;
  4. import java.io.*;
  5. import java.util.Arrays;
  6. import java.util.InputMismatchException;
  7.  
  8. /**
  9.  * https://open.kattis.com/problems/parking
  10.  */
  11. public class Parking {
  12.  
  13.     // helper class
  14.     private static class TruckEvent implements Comparable<TruckEvent> {
  15.         final int value;
  16.         final boolean isArriving;
  17.  
  18.         TruckEvent(int value, boolean isArriving) {
  19.             this.value = value;
  20.             this.isArriving = isArriving;
  21.         }
  22.  
  23.         int getValue() {
  24.             return value;
  25.         }
  26.  
  27.         int getModifier() {
  28.             return isArriving ? 1 : -1;
  29.         }
  30.  
  31.         @Override
  32.         public int compareTo(TruckEvent truckEvent) {
  33.             return Integer.compare(value, truckEvent.value);
  34.         }
  35.     }
  36.  
  37.     public static void main(String[] args) {
  38.         InputReader in = new InputReader(System.in);
  39.         OutputWriter out = new OutputWriter(System.out);
  40.  
  41.         int A = in.readInt();
  42.         int B = in.readInt();
  43.         int C = in.readInt();
  44.  
  45.         TruckEvent[] sortedTruckEvents = new TruckEvent[6];
  46.         int[] prices = {0, A, B * 2, C * 3};
  47.  
  48.         int index = 0;
  49.         for (int i = 0; i < 3; ++i) {
  50.             sortedTruckEvents[i + index] = new TruckEvent(in.readInt(), true);
  51.             sortedTruckEvents[i + 1 + index] = new TruckEvent(in.readInt(), false);
  52.             index++;
  53.         }
  54.  
  55.         Arrays.sort(sortedTruckEvents);
  56.  
  57.         int result = 0;
  58.         int truckCounter = 0;
  59.         int currentTime = 0;
  60.         for (int i = 0; i < sortedTruckEvents.length; ++i) {
  61.             TruckEvent event = sortedTruckEvents[i];
  62.             result += prices[truckCounter] * event.getValue() - currentTime;
  63.             truckCounter += event.getModifier();
  64.             currentTime = event.getValue();
  65.         }
  66.  
  67.         out.print(result);
  68.         out.close();
  69.     }
  70.  
  71.     /**
  72.      * @param n number of primes to find
  73.      * @return primes
  74.      */
  75.     @Generated("Primes")
  76.     private static boolean[] findPrimes(int n) {
  77.         boolean[] primes = new boolean[n + 1];
  78.         Arrays.fill(primes, true); // assume all are primes
  79.         primes[0] = primes[1] = false;
  80.  
  81.         for (int i = 2; i <= Math.sqrt(n); ++i) {
  82.             if (primes[i]) {
  83.                 for (int j = i * i; j <= n; j += i) {
  84.                     primes[j] = false;
  85.                 }
  86.             }
  87.         }
  88.  
  89.         return primes;
  90.     }
  91.  
  92.     @Generated("GCD")
  93.     private static long gcd(long a, long b) {
  94.         if (b == 0 || a == b) {
  95.             return a;
  96.         }
  97.  
  98.         return gcd(b, a % b);
  99.     }
  100.  
  101.     //FAST IO
  102.     @Generated("Fast IO")
  103.     private static class InputReader {
  104.         private InputStream stream;
  105.         private byte[] buf = new byte[1 << 10];
  106.         private int curChar;
  107.         private int numChars;
  108.         private SpaceCharFilter filter;
  109.  
  110.         public InputReader(InputStream stream) {
  111.             this.stream = stream;
  112.         }
  113.  
  114.         public int read() {
  115.             if (numChars == -1)
  116.                 throw new InputMismatchException();
  117.             if (curChar >= numChars) {
  118.                 curChar = 0;
  119.                 try {
  120.                     numChars = stream.read(buf);
  121.                 } catch (IOException e) {
  122.                     throw new InputMismatchException();
  123.                 }
  124.                 if (numChars <= 0)
  125.                     return -1;
  126.             }
  127.             return buf[curChar++];
  128.         }
  129.  
  130.         public int readInt() {
  131.             int c = read();
  132.             while (isSpaceChar(c))
  133.                 c = read();
  134.             int sgn = 1;
  135.             if (c == '-') {
  136.                 sgn = -1;
  137.                 c = read();
  138.             }
  139.             int res = 0;
  140.             do {
  141.                 if (c < '0' || c > '9')
  142.                     throw new InputMismatchException();
  143.                 res *= 10;
  144.                 res += c - '0';
  145.                 c = read();
  146.             } while (!isSpaceChar(c));
  147.             return res * sgn;
  148.         }
  149.  
  150.         public String readString() {
  151.             int c = read();
  152.             while (isSpaceChar(c))
  153.                 c = read();
  154.             StringBuilder res = new StringBuilder();
  155.             do {
  156.                 res.appendCodePoint(c);
  157.                 c = read();
  158.             } while (!isSpaceChar(c));
  159.             return res.toString();
  160.         }
  161.  
  162.         public double readDouble() {
  163.             int c = read();
  164.             while (isSpaceChar(c))
  165.                 c = read();
  166.             int sgn = 1;
  167.             if (c == '-') {
  168.                 sgn = -1;
  169.                 c = read();
  170.             }
  171.             double res = 0;
  172.             while (!isSpaceChar(c) && c != '.') {
  173.                 if (c == 'e' || c == 'E')
  174.                     return res * Math.pow(10, readInt());
  175.                 if (c < '0' || c > '9')
  176.                     throw new InputMismatchException();
  177.                 res *= 10;
  178.                 res += c - '0';
  179.                 c = read();
  180.             }
  181.             if (c == '.') {
  182.                 c = read();
  183.                 double m = 1;
  184.                 while (!isSpaceChar(c)) {
  185.                     if (c == 'e' || c == 'E')
  186.                         return res * Math.pow(10, readInt());
  187.                     if (c < '0' || c > '9')
  188.                         throw new InputMismatchException();
  189.                     m /= 10;
  190.                     res += (c - '0') * m;
  191.                     c = read();
  192.                 }
  193.             }
  194.             return res * sgn;
  195.         }
  196.  
  197.         public long readLong() {
  198.             int c = read();
  199.             while (isSpaceChar(c))
  200.                 c = read();
  201.             int sgn = 1;
  202.             if (c == '-') {
  203.                 sgn = -1;
  204.                 c = read();
  205.             }
  206.             long res = 0;
  207.             do {
  208.                 if (c < '0' || c > '9')
  209.                     throw new InputMismatchException();
  210.                 res *= 10;
  211.                 res += c - '0';
  212.                 c = read();
  213.             } while (!isSpaceChar(c));
  214.             return res * sgn;
  215.         }
  216.  
  217.         public boolean isSpaceChar(int c) {
  218.             if (filter != null)
  219.                 return filter.isSpaceChar(c);
  220.             return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  221.         }
  222.  
  223.         public String next() {
  224.             return readString();
  225.         }
  226.  
  227.         public interface SpaceCharFilter {
  228.             boolean isSpaceChar(int ch);
  229.         }
  230.     }
  231.  
  232.     private static class OutputWriter {
  233.         private final PrintWriter writer;
  234.  
  235.         public OutputWriter(OutputStream outputStream) {
  236.             writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
  237.         }
  238.  
  239.         public OutputWriter(Writer writer) {
  240.             this.writer = new PrintWriter(writer);
  241.         }
  242.  
  243.         public void print(Object... objects) {
  244.             for (int i = 0; i < objects.length; i++) {
  245.                 if (i != 0)
  246.                     writer.print(' ');
  247.                 writer.print(objects[i]);
  248.             }
  249.         }
  250.  
  251.         public void printLine(Object... objects) {
  252.             print(objects);
  253.             writer.println();
  254.         }
  255.  
  256.         public void close() {
  257.             writer.close();
  258.         }
  259.  
  260.         public void flush() {
  261.             writer.flush();
  262.         }
  263.  
  264.     }
  265. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement