Submission #5031578


Source Code Expand

import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.stream.IntStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.util.StringTokenizer;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author mikit
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        LightScanner in = new LightScanner(inputStream);
        LightWriter out = new LightWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, LightScanner in, LightWriter out) {
            // out.setBoolLabel(LightWriter.BoolLabel.YES_NO_FIRST_UP);
            int n = in.ints();
            int[] t = in.ints(n);
            int ans = 1000000;
            for (int i = 0; i < (1 << n); i++) {
                int x = 0, y = 0;
                for (int j = 0; j < n; j++) {
                    if ((i & (1 << j)) == 0) {
                        x += t[j];
                    } else {
                        y += t[j];
                    }
                }
                ans = Math.min(ans, Math.max(x, y));
            }
            out.ans(ans).ln();
        }

    }

    static class LightWriter implements AutoCloseable {
        private final Writer out;
        private boolean autoflush = false;
        private boolean breaked = true;

        public LightWriter(Writer out) {
            this.out = out;
        }

        public LightWriter(OutputStream out) {
            this(new BufferedWriter(new OutputStreamWriter(out, Charset.defaultCharset())));
        }

        public LightWriter print(char c) {
            try {
                out.write(c);
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter print(String s) {
            try {
                out.write(s, 0, s.length());
                breaked = false;
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
            return this;
        }

        public LightWriter ans(String s) {
            if (!breaked) {
                print(' ');
            }
            return print(s);
        }

        public LightWriter ans(int i) {
            return ans(Integer.toString(i));
        }

        public LightWriter ln() {
            print(System.lineSeparator());
            breaked = true;
            if (autoflush) {
                try {
                    out.flush();
                } catch (IOException ex) {
                    throw new UncheckedIOException(ex);
                }
            }
            return this;
        }

        public void close() {
            try {
                out.close();
            } catch (IOException ex) {
                throw new UncheckedIOException(ex);
            }
        }

    }

    static class LightScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public LightScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
        }

        public String string() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new UncheckedIOException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int ints() {
            return Integer.parseInt(string());
        }

        public int[] ints(int length) {
            return IntStream.range(0, length).map(x -> ints()).toArray();
        }

    }
}

Submission Info

Submission Time
Task A - 高橋君とお肉
User mikit
Language Java8 (OpenJDK 1.8.0)
Score 100
Code Size 4375 Byte
Status AC
Exec Time 222 ms
Memory 27988 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 100 / 100
Status
AC × 3
AC × 19
Set Name Test Cases
Sample subtask0-sample-01.txt, subtask0-sample-02.txt, subtask0-sample-03.txt
All 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 AC 222 ms 25940 KB
subtask0-sample-02.txt AC 149 ms 26580 KB
subtask0-sample-03.txt AC 150 ms 23508 KB
subtask1-01.txt AC 155 ms 25684 KB
subtask1-02.txt AC 161 ms 26452 KB
subtask1-03.txt AC 160 ms 25940 KB
subtask1-04.txt AC 155 ms 26324 KB
subtask1-05.txt AC 162 ms 24788 KB
subtask1-06.txt AC 159 ms 25684 KB
subtask1-07.txt AC 157 ms 27600 KB
subtask1-08.txt AC 157 ms 25684 KB
subtask1-09.txt AC 153 ms 25300 KB
subtask1-10.txt AC 160 ms 25684 KB
subtask1-11.txt AC 153 ms 26196 KB
subtask1-12.txt AC 159 ms 25680 KB
subtask1-13.txt AC 159 ms 26196 KB
subtask1-14.txt AC 163 ms 27988 KB
subtask1-15.txt AC 154 ms 24532 KB
subtask1-16.txt AC 158 ms 25684 KB