Submission #2047695


Source Code Expand

import java.io.*;
import java.util.*;

public class Main {
	private static final int mod = (int) 1E9 + 7, bufsize = (1 << 13);
	private static int iNextByte, iNextIndex, iReadByteCount, oNextIndex;
	private static final byte ibuf[] = new byte[bufsize], obuf[] = new byte[bufsize];
	private static InputStream input = System.in;
	private static OutputStream output = System.out;
	private static PrintStream err = System.err;

	private Main() throws Exception {
		if (local) input = new FileInputStream(new File("").getAbsolutePath() + "/src/zzz_input");
		if (local) output = new FileOutputStream(new File("").getAbsolutePath() + "/src/zzz_output");
		readByte();
		solve();
		input.close();
		flushOutBuf();
	}

	public static void main(String[] args) {
		try {
			new Main();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private int readByte() throws IOException {
		if (iNextIndex >= iReadByteCount) {
			iReadByteCount = input.read(ibuf, 0, bufsize);
			if (iReadByteCount == -1) return (iNextByte = -1);
			iNextIndex = 0;
		}
		return (iNextByte = ibuf[iNextIndex++]);
	}

	private char nc() throws IOException {
		while (iNextByte <= ' ') readByte();
		char res = (char) iNextByte;
		readByte();
		return res;
	}

	private int ni() throws IOException {
		int res = 0;
		while (iNextByte <= ' ') readByte();
		boolean minus = (iNextByte == '-');
		if (minus) readByte();
		if (iNextByte < '0' || iNextByte > '9') throw new RuntimeException();
		do {res = (res << 1) + (res << 3) + iNextByte - '0';} while (readByte() >= '0' && iNextByte <= '9');
		return minus ? -res : res;
	}

	private long nl() throws IOException {
		long res = 0;
		while (iNextByte <= ' ') readByte();
		boolean minus = (iNextByte == '-');
		if (minus) readByte();
		if (iNextByte < '0' || iNextByte > '9') throw new RuntimeException();
		do {res = (res << 1) + (res << 3) + iNextByte - '0';} while (readByte() >= '0' && iNextByte <= '9');
		return minus ? -res : res;
	}

	private double nd() throws IOException {
		double pre = 0.0, suf = 0.0, div = 1.0;
		while (iNextByte <= ' ') readByte();
		boolean minus = (iNextByte == '-');
		if (minus) readByte();
		if (iNextByte < '0' || iNextByte > '9') throw new RuntimeException();
		do {pre = 10 * pre + (iNextByte - '0');} while (readByte() >= '0' && iNextByte <= '9');
		if (iNextByte == '.') while (readByte() >= '0' && iNextByte <= '9') suf += (iNextByte - '0') / (div *= 10);
		return minus ? -(pre + suf) : (pre + suf);
	}

	private String ns() throws IOException {
		while (iNextByte <= ' ') readByte();
		StringBuilder sb = new StringBuilder();
		while (iNextByte > ' ') {
			sb.append((char) iNextByte);
			readByte();
		}
		return sb.toString();
	}

	private char[] nc(int n) throws IOException {
		char a[] = new char[n];
		for (int i = 0; i < n; ++i) a[i] = nc();
		return a;
	}

	private char[][] nc(int r, int c) throws IOException {
		char a[][] = new char[r][c];
		for (int i = 0; i < r; ++i) a[i] = nc(c);
		return a;
	}

	private int[] ni(int n) throws IOException {
		int a[] = new int[n];
		for (int i = 0; i < n; ++i) a[i] = ni();
		return a;
	}

	private int[][] ni(int r, int c) throws IOException {
		int a[][] = new int[r][c];
		for (int i = 0; i < r; ++i) a[i] = ni(c);
		return a;
	}

	private long[] nl(int n) throws IOException {
		long a[] = new long[n];
		for (int i = 0; i < n; ++i) a[i] = nl();
		return a;
	}

	private long[][] nl(int r, int c) throws IOException {
		long a[][] = new long[r][c];
		for (int i = 0; i < r; ++i) a[i] = nl(c);
		return a;
	}

	private double[] nd(int n) throws IOException {
		double a[] = new double[n];
		for (int i = 0; i < n; ++i) a[i] = nd();
		return a;
	}

	private double[][] nd(int r, int c) throws IOException {
		double a[][] = new double[r][c];
		for (int i = 0; i < r; ++i) a[i] = nd(c);
		return a;
	}

	private String[] ns(int n) throws IOException {
		String a[] = new String[n];
		for (int i = 0; i < n; ++i) a[i] = ns();
		return a;
	}

	private String[][] ns(int r, int c) throws IOException {
		String a[][] = new String[r][c];
		for (int i = 0; i < r; ++i) a[i] = ns(c);
		return a;
	}

	private void flushOutBuf() {
		try {
			if (oNextIndex <= 0) return;
			output.write(obuf, 0, oNextIndex);
			output.flush();
			oNextIndex = 0;
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	private <T> void print(T ob) {
		String s = ob + "";
		for (int i = 0, N = s.length(); i < N; ++i) {
			obuf[oNextIndex++] = (byte) s.charAt(i);
			if (oNextIndex >= bufsize) flushOutBuf();
		}
	}

	private <T> void println(T ob) {
		print(ob + "\n");
	}

	private static final boolean local = false;

	private void solve() throws Exception {
		int N = ni(), a[][] = ni(2, N);
		int sum = 0, curA = 0, curB = 0;
		for(int i = 0; i < N; ++i) curB += a[1][i];
		for(int i = 0; i < N; ++i) {
			curA += a[0][i];
			sum = Math.max(curA + curB, sum);
			curB -= a[1][i];
		}
		println(sum);
	}
}

Submission Info

Submission Time
Task C - Candies
User Compet
Language Java8 (OpenJDK 1.8.0)
Score 300
Code Size 5092 Byte
Status AC
Exec Time 69 ms
Memory 21204 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 4
AC × 16
Set Name Test Cases
Sample sample01.txt, sample02.txt, sample03.txt, sample04.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample01.txt, sample02.txt, sample03.txt, sample04.txt
Case Name Status Exec Time Memory
01.txt AC 69 ms 19668 KiB
02.txt AC 68 ms 21076 KiB
03.txt AC 67 ms 17364 KiB
04.txt AC 68 ms 21204 KiB
05.txt AC 69 ms 16724 KiB
06.txt AC 68 ms 18644 KiB
07.txt AC 69 ms 18772 KiB
08.txt AC 67 ms 18132 KiB
09.txt AC 66 ms 18132 KiB
10.txt AC 68 ms 17108 KiB
11.txt AC 66 ms 18004 KiB
12.txt AC 68 ms 19284 KiB
sample01.txt AC 69 ms 21204 KiB
sample02.txt AC 66 ms 19284 KiB
sample03.txt AC 69 ms 18132 KiB
sample04.txt AC 66 ms 15828 KiB