1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#define __STDC_FORMAT_MACROS
#include <inttypes.h>
#include <cstdio>

#define MIN(a,b) ((a) < (b)) ? (a) : (b)
#define MAX(a,b) ((a) > (b)) ? (a) : (b)

uint32_t c[2000][2000];

int main(void) {
        int n;
        scanf("%d", &n);
	int b[n], d[n], y, z, p;
	uint64_t s = 0;
        for (int i = 0; i < n; i++)
        {
		for (int j = 0; j < n-i; j++)
		{
			scanf("%" SCNu32, &c[j][i]);
		}
        }

	for (int i = 0; i < n; i++)
	{
		b[i] = 0;
		d[i] = i;
	}
	for (int i = 1; i < n; i++)
	{
		for (int j = n-i-1; j >= 0; j--)
		{
			p = -1;
			for (int k = 0; k <= i; k++)
			{
				y = j+k;
				if (c[b[y]][d[y]] > c[i][j])
				{
					if (p != -1 && c[b[y]][d[y]] > c[b[p]][d[p]] || p == -1)
						p = y;
				}
			}
			if (p != -1)
			{
				b[p] = i;
				d[p] = j;
			}
		}
	}
//	for (int i = 0; i < n; i++)
//		printf("%d%c", b[i], i < n-1 ? ' ' : '\n');
//	for (int i = 0; i < n; i++)
//		printf("%d%c", d[i], i < n-1 ? ' ' : '\n');
	for (int i = 0; i < n; i++)
		s += c[b[i]][d[i]];
	printf("%" PRIu64 "\n", s);
        return 0;
}