Submission #2133835


Source Code Expand

import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.NoSuchElementException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	void run() {
		FastScanner sc = new FastScanner();
		int n = (int) sc.nextLong();
		int m = (int) sc.nextLong();
		int k = (int) sc.nextLong();
		long[] a = new long[n];
		for (int i = 0; i < n; ++i) {
			a[i] = sc.nextLong();
		}
		long[][] f = new long[n][k];
		for (int i = 0; i < f.length; ++i)
			for (int j = 0; j < f[i].length; ++j)
				f[i][j] = -Long.MAX_VALUE / 3;

		ArrayDeque<Long>[] dq = new ArrayDeque[k];
		for (int i = 0; i < dq.length; ++i)
			dq[i] = new ArrayDeque();
		for (int i = 0; i < f.length; ++i) {
			for (int j = k - 1; j >= 0; --j) {
				long add = a[i] * (j + 1);
				long base;
				if (j > 0) {
					if (dq[j - 1].isEmpty())
						continue;
					else
						base = dq[j - 1].peekLast();
				} else {
					base = 0;
				}
				f[i][j] = Math.max(f[i][j], add + base);
				int cnt = 0;
				while (!dq[j].isEmpty() && dq[j].peekFirst() < f[i][j]) {
					dq[j].pollFirst();
					++cnt;
				}
				while (cnt-- >= 0) {
					dq[j].addFirst(f[i][j]);
				}
				while (dq[j].size() > m)
					dq[j].pollLast();
			}
		}
		long ans = 0;
		for (int i = 0; i < n; ++i) {
			ans = Math.max(ans, f[i][k - 1]);
		}
		System.out.println(ans);
	}

	class FastScanner {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;

		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[ptr++];
			else
				return -1;
		}

		private boolean isPrintableChar(int c) {
			return 33 <= c && c <= 126;
		}

		private void skipUnprintable() {
			while (hasNextByte() && !isPrintableChar(buffer[ptr]))
				ptr++;
		}

		public boolean hasNext() {
			skipUnprintable();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while (true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if (b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}

	void tr(Object... objects) {
		System.out.println(Arrays.deepToString(objects));
	}
}

Submission Info

Submission Time
Task A - Struck Out
User fortoobye
Language Java8 (OpenJDK 1.8.0)
Score 200
Code Size 3292 Byte
Status TLE
Exec Time 2110 ms
Memory 592428 KB

Compile Error

Note: ./Main.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.

Judge Result

Set Name Sample subtask1 subtask2 subtask3 All
Score / Max Score 0 / 0 0 / 100 200 / 200 0 / 300 0 / 100
Status
AC × 3
AC × 6
TLE × 4
AC × 12
AC × 20
TLE × 1
AC × 29
TLE × 16
MLE × 1
Set Name Test Cases
Sample sample_1.txt, sample_2.txt, sample_3.txt
subtask1 sample_2.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt
subtask2 sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt
subtask3 sample_1.txt, sample_2.txt, sample_3.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt
All sample_1.txt, sample_2.txt, sample_3.txt, sample_1.txt, sample_2.txt, sample_3.txt, subtask_1_1.txt, subtask_1_2.txt, subtask_1_3.txt, subtask_1_4.txt, subtask_1_5.txt, subtask_1_6.txt, subtask_1_7.txt, subtask_1_8.txt, subtask_1_9.txt, subtask_2_1.txt, subtask_2_2.txt, subtask_2_3.txt, subtask_2_4.txt, subtask_2_5.txt, subtask_2_6.txt, subtask_2_7.txt, subtask_2_8.txt, subtask_2_9.txt, subtask_3_1.txt, subtask_3_2.txt, subtask_3_3.txt, subtask_3_4.txt, subtask_3_5.txt, subtask_3_6.txt, subtask_3_7.txt, subtask_3_8.txt, subtask_3_9.txt, subtask_4_1.txt, subtask_4_10.txt, subtask_4_11.txt, subtask_4_12.txt, subtask_4_13.txt, subtask_4_2.txt, subtask_4_3.txt, subtask_4_4.txt, subtask_4_5.txt, subtask_4_6.txt, subtask_4_7.txt, subtask_4_8.txt, subtask_4_9.txt
Case Name Status Exec Time Memory
sample_1.txt AC 69 ms 23380 KB
sample_2.txt AC 67 ms 17364 KB
sample_3.txt AC 69 ms 18388 KB
subtask_1_1.txt AC 79 ms 17876 KB
subtask_1_2.txt TLE 2106 ms 423060 KB
subtask_1_3.txt TLE 2108 ms 579488 KB
subtask_1_4.txt AC 170 ms 53032 KB
subtask_1_5.txt AC 411 ms 135860 KB
subtask_1_6.txt AC 106 ms 31244 KB
subtask_1_7.txt TLE 2110 ms 448404 KB
subtask_1_8.txt TLE 2110 ms 571260 KB
subtask_1_9.txt AC 185 ms 63784 KB
subtask_2_1.txt AC 105 ms 22852 KB
subtask_2_2.txt AC 77 ms 21204 KB
subtask_2_3.txt AC 81 ms 20052 KB
subtask_2_4.txt AC 85 ms 19668 KB
subtask_2_5.txt AC 73 ms 21204 KB
subtask_2_6.txt AC 72 ms 19284 KB
subtask_2_7.txt AC 86 ms 23636 KB
subtask_2_8.txt AC 100 ms 21036 KB
subtask_2_9.txt AC 85 ms 23892 KB
subtask_3_1.txt AC 1592 ms 415484 KB
subtask_3_2.txt AC 680 ms 175564 KB
subtask_3_3.txt AC 785 ms 190376 KB
subtask_3_4.txt AC 581 ms 187368 KB
subtask_3_5.txt AC 171 ms 49264 KB
subtask_3_6.txt AC 304 ms 101736 KB
subtask_3_7.txt TLE 2049 ms 428804 KB
subtask_3_8.txt AC 245 ms 63024 KB
subtask_3_9.txt AC 463 ms 140924 KB
subtask_4_1.txt TLE 2107 ms 592428 KB
subtask_4_10.txt MLE 1356 ms 552704 KB
subtask_4_11.txt TLE 2091 ms 543264 KB
subtask_4_12.txt TLE 2107 ms 546520 KB
subtask_4_13.txt TLE 2107 ms 552392 KB
subtask_4_2.txt TLE 2106 ms 551888 KB
subtask_4_3.txt TLE 2107 ms 574412 KB
subtask_4_4.txt TLE 2107 ms 563656 KB
subtask_4_5.txt TLE 2107 ms 556320 KB
subtask_4_6.txt AC 1528 ms 360568 KB
subtask_4_7.txt TLE 2106 ms 363040 KB
subtask_4_8.txt TLE 2107 ms 590892 KB
subtask_4_9.txt TLE 2106 ms 387640 KB