제출 #1099546

#제출 시각아이디문제언어결과실행 시간메모리
1099546crispxxStove (JOI18_stove)C++14
20 / 100
1008 ms348 KiB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define nl " \n"
#define pb emplace_back
#define all(x) x.begin(), x.end()

template <class F, class S> 
void chmin(F &a, S b) { 
	if(a > b) a = b;
}

template <class F, class S> 
void chmax(F &a, S b) { 
	if(a < b) a = b;
}


void run_case() {
	int n, k; 
	cin >> n >> k;
	
	vt<int> a(n);
	for(auto &i : a) {
		cin >> i;
	}
	
	auto Brute = [&](){
		int ans = *max_element(all(a));
		for(int mask = 0; mask < (1 << n); mask++) {
			if(mask % 2 == 0 || __builtin_popcount(mask) != k) continue;
			int tot = 0, j = 0, mx = 0;
			for(int i = 0; i < n; i++) {
				if(mask >> i & 1) {
					tot += mx;
					mx = 0;
					j = i;
				}
				chmax(mx, a[i] - a[j] + 1);
			}
			chmin(ans, tot + mx);
		}
		return ans;
	};
	cout << Brute() << nl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int tt = 1;
	// cin >> tt;
	for(int i = 0; i < tt; i++) {
		run_case();
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...