Submission #1964163


Source Code Expand

import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

class Main {

	public void run() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[][] a = new long[n][2];
		for (int i = 0; i < n; ++i) {
			a[i][0] = sc.nextLong();
			a[i][1] = sc.nextLong();
		}
		Arrays.sort(a, new Comparator<long[]>() {
			@Override
			public int compare(long[] arg0, long[] arg1) {
				return -Long.compare(arg0[0] + arg0[1], arg1[0] + arg1[1]);
			}
		});
		long ans = Long.MAX_VALUE / 3;
		long[][][] g = new long[2][n + 1][n + 1];
		for (int i = 0; i < g.length; ++i)
			for (int j = 0; j < g[i].length; ++j)
				for (int k = 0; k < g[i][j].length; ++k)
					g[i][j][k] = Long.MAX_VALUE / 10;
		g[0][0][0] = 0;
		for (int i = 0; i < n; ++i) {
			for (int k = 0; k <= 1; ++k) {
				for (int j = 0; j <= i - k; ++j) {
					g[k][i - j - k][j + 1] = Math.min(g[k][i - j - k][j + 1],
							g[k][i - j][j] + a[i][0] + j * (a[i][0] + a[i][1]));
					g[k][i - j - k + 1][j] = Math.min(g[k][i - j - k + 1][j],
							g[k][i - j - k][j] + a[i][1] + (i - j - k) * (a[i][0] + a[i][1]));
				}
			}
			if (n % 2 == 1) {
				for (int j = 0; j <= i; ++j) {
					g[1][i - j][j] = Math.min(g[1][i - j][j],
							g[0][i - j][j] + (n - 1) / 2 * (a[i][0] + a[i][1]));
				}
			}
		}
		for (int i = 0; i < g.length; ++i)
			for (int j = 0; j < g[i].length; ++j)
				for (int k = 0; k < g[i][j].length; ++k) {
					if (i + j + k == n) {
						ans = Math.min(ans, g[i][j][k]);
					}
				}
		System.out.println(ans);
	}

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

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

Submission Info

Submission Time
Task F - Intervals
User fortoobye
Language Java8 (OpenJDK 1.8.0)
Score 0
Code Size 1812 Byte
Status MLE
Exec Time 1121 ms
Memory 658216 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 1000
Status
AC × 2
AC × 8
MLE × 37
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, 016.txt, 017.txt, 018.txt, 019.txt, 020.txt, 021.txt, 022.txt, 023.txt, 024.txt, 025.txt, 026.txt, 027.txt, 028.txt, 029.txt, 030.txt, 031.txt, 032.txt, 033.txt, 034.txt, 035.txt, 036.txt, 037.txt, 038.txt, 039.txt, 040.txt, 041.txt, 042.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt MLE 1116 ms 650168 KB
001.txt AC 385 ms 125560 KB
002.txt MLE 1039 ms 583916 KB
003.txt MLE 923 ms 359996 KB
004.txt MLE 1110 ms 641248 KB
005.txt MLE 598 ms 246828 KB
006.txt MLE 1078 ms 656964 KB
007.txt MLE 616 ms 247060 KB
008.txt MLE 995 ms 480892 KB
009.txt AC 285 ms 79204 KB
010.txt MLE 1121 ms 633372 KB
011.txt MLE 586 ms 245844 KB
012.txt MLE 1078 ms 655852 KB
013.txt AC 282 ms 78884 KB
014.txt MLE 1097 ms 648268 KB
015.txt AC 428 ms 122152 KB
016.txt MLE 995 ms 469884 KB
017.txt MLE 826 ms 353544 KB
018.txt MLE 995 ms 585672 KB
019.txt MLE 655 ms 249012 KB
020.txt AC 95 ms 23892 KB
021.txt AC 97 ms 19028 KB
022.txt MLE 965 ms 485748 KB
023.txt MLE 1032 ms 595816 KB
024.txt MLE 1000 ms 486956 KB
025.txt MLE 946 ms 458988 KB
026.txt MLE 1013 ms 490640 KB
027.txt MLE 1096 ms 643700 KB
028.txt MLE 1070 ms 649620 KB
029.txt MLE 1069 ms 650916 KB
030.txt MLE 998 ms 489676 KB
031.txt MLE 1062 ms 467912 KB
032.txt MLE 1073 ms 650228 KB
033.txt MLE 1079 ms 642036 KB
034.txt MLE 1079 ms 638388 KB
035.txt MLE 974 ms 483744 KB
036.txt MLE 1084 ms 658216 KB
037.txt MLE 1042 ms 476404 KB
038.txt MLE 984 ms 483084 KB
039.txt MLE 1034 ms 581912 KB
040.txt MLE 996 ms 488480 KB
041.txt MLE 1114 ms 635096 KB
042.txt MLE 1082 ms 655512 KB
example0.txt AC 96 ms 21204 KB
example1.txt AC 98 ms 20948 KB