Cod sursa(job #2265256)

Utilizator turculetVictor Turculet turculet Data 20 octombrie 2018 21:23:29
Problema A+B Scor 0
Compilator java Status done
Runda Arhiva de probleme Marime 4.23 kb
package md.turculet;

import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Random;

import static java.lang.Character.isDigit;

public final class Main {

    public static final String IN_FILE = "adunare.in";

    public static final String OUT_FILE = "adunare.out";
//    private static final Random randomGen = new Random();

//    private static int random(final int lower, final int upper) {
//        return lower + randomGen.nextInt(upper - lower + 1);
//    }
//
//    private static void swap(final int[] values, final int i, final int j) {
//        final int aux = values[i];
//        values[i] = values[j];
//        values[j] = aux;
//    }
//
//    private static int partition(final int[] values, final int from, final int to) {
//        final int pivot = values[random(from, to)];
//        int i = from - 1;
//        int j = to + 1;
//        while (true){
//            for (i++; values[i] < pivot; i++) ;
//            for (j--; values[j] > pivot; j--) ;
//            if (i >= j) {
//                return j;
//            }
//            swap(values, i, j);
//        }
//    }
//
//    private static int orderStatistics(final int[] values, final int from, final int to, final int k) {
//        if (from == to) {
//            return values[from];
//        }
//        final int split = partition(values, from, to);
//        return k <= split - from + 1
//                ? orderStatistics(values, from, split, k)
//                : orderStatistics(values, split + 1, to, k - (split - from + 1));
//    }
//
//    public static int orderStatistics(final int[] values, final int k) {
//        return orderStatistics(values, 0, values.length - 1, k);
//    }
//
//    public static int[] readValues(final FastScanner scanner, final int n) throws IOException {
//        final int[] values = new int[n];
//        for (int i = 0; i < n; i++) {
//            values[i] = scanner.nextInt();
//        }
//        return values;
//    }

    public static void main(final String[] args) throws IOException {

        try (final FastScanner scanner = new FastScanner(IN_FILE); final PrintWriter writer = new PrintWriter(OUT_FILE)) {

            final int n = scanner.nextInt();
            final int k = scanner.nextInt();
//            final int[] values = readValues(scanner, n);

//            final int result = orderStatistics(values, k);

            writer.println(n + k);
        }

    }

    public final static class FastScanner implements AutoCloseable {

        private static final int BUFFER_SIZE = 1 << 16;
        private final DataInputStream stream;
        private final byte[] buffer = new byte[BUFFER_SIZE];
        private int bufferPointer = 0;
        private int bytesRead = 0;

        public FastScanner(final String fileName) throws IOException {
            stream = new DataInputStream(new FileInputStream(fileName));
        }

        public int nextInt() throws IOException {
            byte c;
            do {
                c = read();
            } while (c != '-' && !isDigit(c));
            final boolean isNegative = c == '-';
            if (isNegative) {
                c = read();
            }
            int value = 0;
            do {
                value = value * 10 + (c - '0');
                c = read();
            } while (isDigit(c));
            return isNegative ? -value : value;
        }

        private byte read() throws IOException {
            final byte c = tryRead();
            if (c == -1) {
                throw new IOException("Reached end of stream!");
            }
            return c;
        }

        private byte tryRead() throws IOException {
            if (bufferPointer == bytesRead) {
                bufferPointer = 0;
                bytesRead = stream.read(buffer, 0, BUFFER_SIZE);
                if (bytesRead == -1) {
                    bytesRead = 0;
                    return -1;
                }
            }
            return buffer[bufferPointer++];
        }

        @Override
        public void close() throws IOException {
            stream.close();
        }
    }

}