Submission #6570027


Source Code Expand

Copy
import java.io.*;
import java.nio.CharBuffer;
import java.util.NoSuchElementException;

public class Main {

    public static void main(String[] args) {
        SimpleScanner scanner = new SimpleScanner(System.in);
        PrintWriter writer = new PrintWriter(System.out);

        int n = scanner.nextInt();
        int[] a = new int[n + 1];
        int[] b = new int[n];
        for (int i = 0; i <= n; ++i)
            a[i] = scanner.nextInt();
        for (int i = 0; i < n; ++i)
            b[i] = scanner.nextInt();
        long ans = 0;
        int t;
        for (int i = 0; i < n; ++i) {
            t = Math.min(a[i], b[i]);
            ans += t;
            a[i] -= t;
            b[i] -= t;
            t = Math.min(b[i], a[i + 1]);
            ans += t;
            a[i + 1] -= t;
            b[i] -= t;
        }
        writer.println(ans);
        writer.close();
    }

    private static class SimpleScanner {

        private static final int BUFFER_SIZE = 10240;

        private Readable in;
        private CharBuffer buffer;
        private boolean eof;

        SimpleScanner(InputStream in) {
            this.in = new BufferedReader(new InputStreamReader(in));
            buffer = CharBuffer.allocate(BUFFER_SIZE);
            buffer.limit(0);
            eof = false;
        }


        private char read() {
            if (!buffer.hasRemaining()) {
                buffer.clear();
                int n;
                try {
                    n = in.read(buffer);
                } catch (IOException e) {
                    n = -1;
                }
                if (n <= 0) {
                    eof = true;
                    return '\0';
                }
                buffer.flip();
            }
            return buffer.get();
        }

        void checkEof() {
            if (eof)
                throw new NoSuchElementException();
        }

        char nextChar() {
            checkEof();
            char b = read();
            checkEof();
            return b;
        }

        String next() {
            char b;
            do {
                b = read();
                checkEof();
            } while (Character.isWhitespace(b));
            StringBuilder sb = new StringBuilder();
            do {
                sb.append(b);
                b = read();
            } while (!eof && !Character.isWhitespace(b));
            return sb.toString();
        }

        int nextInt() {
            return Integer.valueOf(next());
        }

        long nextLong() {
            return Long.valueOf(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Submission Info

Submission Time
Task C - City Savers
User brainfxxk
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 2787 Byte
Status AC
Exec Time 216 ms
Memory 46856 KB

Judge Result

Set Name All Sample
Score / Max Score 300 / 300 0 / 0
Status
AC × 17
AC × 3
Set Name Test Cases
All sample_01, sample_02, sample_03, testcase_01, testcase_02, testcase_03, testcase_04, testcase_05, testcase_06, testcase_07, testcase_08, testcase_09, testcase_10, testcase_11, testcase_12, testcase_13, testcase_14
Sample sample_01, sample_02, sample_03
Case Name Status Exec Time Memory
sample_01 AC 72 ms 18900 KB
sample_02 AC 67 ms 17492 KB
sample_03 AC 69 ms 20052 KB
testcase_01 AC 187 ms 37800 KB
testcase_02 AC 179 ms 36296 KB
testcase_03 AC 209 ms 45296 KB
testcase_04 AC 210 ms 46856 KB
testcase_05 AC 143 ms 32764 KB
testcase_06 AC 167 ms 41192 KB
testcase_07 AC 196 ms 44072 KB
testcase_08 AC 213 ms 44556 KB
testcase_09 AC 204 ms 39900 KB
testcase_10 AC 211 ms 46056 KB
testcase_11 AC 215 ms 40764 KB
testcase_12 AC 86 ms 20180 KB
testcase_13 AC 216 ms 40616 KB
testcase_14 AC 68 ms 25044 KB