Submission #345148

# Submission time Handle Problem Language Result Execution time Memory
345148 2021-01-07T05:24:13 Z l3nl3 K blocks (IZhO14_blocks) C++14
0 / 100
1 ms 364 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>  

#define exit exit(false)

//#define here() cerr << "herewego\n";
#define show(x) cerr << #x << ": " << x << '\n';

#define int long long
//#define double long double

#define all(a) a.begin(), a.end()
#define whole(a, p, q) a+p, a+p+q

#define ioio() ios_base::sync_with_stdio (0); cin.tie (0); cout.tie (0);

using namespace std;

//using namespace __gnu_pbds;   
//typedef tree <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;  

const int mxsz = 1e5 + 7;

int n, k, a[mxsz], t[mxsz * 4], mn;

void build (int v, int tl, int tr) {
	if (tl == tr) {
		t[v] = a[tl];
		return;
	}
	int tm = (tl + tr) >> 1;
	int lf = (v << 1);
	int rg = (v << 1 | 1);
	build (lf, tl, tm);
	build (rg, tm+1, tr);
	t[v] = max (t[lf], t[rg]);
}

int get (int v, int tl, int tr, int l, int r) {
	if (l <= tl && tr <= r) {
		return t[v];
	}
	if (tr < l || r < tl) {
		return 0;
	}
	int tm = (tl + tr) >> 1;
	int lf = (v << 1);
	int rg = (v << 1 | 1);
	return max(get (lf, tl, tm, l, r), get (rg, tm+1, tr, l, r));
}

int get (int l, int r) {
	return get (1, 1, n, l, r);
}

signed main () { ioio();
	cin >> n >> k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	build (1, 1, n);
	if (k == 1) {
		cout << get (1, n);
		exit;
	}
	if (k == 2) {
		for (int a = 2; a < n; a++) {
			if (a == 2) {
				mn = get (1, a-1) + get (a, n);
				continue;
			}
			mn = min (mn, get (1, a-1) + get (a, n));
		}
		cout << mn;
		exit;
	}
	if (k == 3) {
		for (int a = 2; a < n-1; a++) {
			for (int b = a+1; b < n; b++) {
				if (a == 2 && b == 3) {
					mn = get (1, a-1) + get (a, b-1) + get (b, n);
					continue;
				}
				mn = min (mn, get (1, a-1) + get (a, b-1) + get (b, n));
			}
		}
		cout << mn;
		exit;
	}
	if (k == 4) {
		for (int a = 2; a < n-2; a++) {
			for (int b = a+1; b < n-1; b++) {
				for (int c = b+1; c < n; c++) {
					if (a == 2 && b == 3 && c == 4) {
						mn = get (1, a-1) + get (a, b-1) + get (b, c-1) + get (c, n);
						continue;
					}
					mn = min (mn, get (1, a-1) + get (a, b-1) + get (b, c-1) + get (c, n));
				}
			}
		}
		cout << mn;
		exit;
	}
	if (k == 5) {
		for (int a = 2; a < n-3; a++) {
			for (int b = a+1; b < n-2; b++) {
				for (int c = b+1; c < n-1; c++) {
					for (int d = c+1; d < n; d++) {
						if (a == 2 && b == 3 && c == 4 && d == 5) {
							mn = get (1, a-1) + get (a, b-1) + get (b, c-1) + get (c, d-1) + get (d, n);
							continue;
						}
						mn = min (mn, get (1, a-1) + get (a, b-1) + get (b, c-1) + get (c, d-1) + get (d, n));
					}
				}
			}
		}
		cout << mn;
		exit;
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -