Submission #241208


Source Code Expand

Copy
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * Created by hama_du on 2014/09/27.
 */
public class Main {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int n = in.nextInt();
        int[] a = new int[n];
        int sum = 0;
        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            sum += a[i];
        }

        int min = 1000;
        for (int i = 0 ; i < (1<<n) ; i++) {
            int n1 = 0;
            for (int j = 0 ; j < n ; j++) {
                if ((i & (1<<j)) >= 1) {
                    n1 += a[j];
                }
            }
            min = Math.min(min, Math.max(n1, sum - n1));
        }
        out.println(min);
        out.flush();
    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int next() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public long nextLong() {
            int c = next();
            while (isSpaceChar(c))
                c = next();
            long sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = next();
            }
            long res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = next();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}

Submission Info

Submission Time
Task A - 高橋君とお肉
User hamadu
Language Java (OpenJDK 1.7.0)
Score 100
Code Size 3257 Byte
Status
Exec Time 357 ms
Memory 20696 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt
All 100 / 100 subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt, subtask1-01.txt, subtask1-02.txt, subtask1-03.txt, subtask1-04.txt, subtask1-05.txt, subtask1-06.txt, subtask1-07.txt, subtask1-08.txt, subtask1-09.txt, subtask1-10.txt, subtask1-11.txt, subtask1-12.txt, subtask1-13.txt, subtask1-14.txt, subtask1-15.txt, subtask1-16.txt
Case Name Status Exec Time Memory
subtask0-sample-01.txt 339 ms 20656 KB
subtask0-sample-02.txt 345 ms 20644 KB
subtask0-sample-03.txt 346 ms 20688 KB
subtask1-01.txt 346 ms 20664 KB
subtask1-02.txt 346 ms 20676 KB
subtask1-03.txt 340 ms 20640 KB
subtask1-04.txt 348 ms 20692 KB
subtask1-05.txt 338 ms 20640 KB
subtask1-06.txt 340 ms 20644 KB
subtask1-07.txt 357 ms 20676 KB
subtask1-08.txt 345 ms 20696 KB
subtask1-09.txt 339 ms 20644 KB
subtask1-10.txt 347 ms 20656 KB
subtask1-11.txt 340 ms 20644 KB
subtask1-12.txt 340 ms 20648 KB
subtask1-13.txt 340 ms 20672 KB
subtask1-14.txt 338 ms 20644 KB
subtask1-15.txt 338 ms 20676 KB
subtask1-16.txt 338 ms 20644 KB