Submission #170403

#TimeUsernameProblemLanguageResultExecution timeMemory
170403LightningK blocks (IZhO14_blocks)C++14
0 / 100
1070 ms504 KiB
#include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <set> #include <map> #include <iomanip> #include <stack> #include <queue> #include <deque> using namespace std; typedef long long ll; typedef pair <int, int> pii; #define sz(a) (int)a.size() #define all(a) a.begin(), a.end() #define pb push_back #define ppb pop_back #define mkp make_pair #define F first #define S second #define show(a) cerr << #a <<" -> "<< a <<"\n" #define fo(a, b, c, d) for(int (a) = (b); (a) <= (c); (a) += (d)) #define foo(a, b, c ,d) for(int (a) = (b); (a) >= (c); (a) -= (d)) //#define int ll const int N = 205; const int INF = 2e9 + 5; int n, k, a[N], ans = INF; bool End[N]; void rec(int pos, int cnt, int sum, int mx) { if(pos == n) { ans = min(ans, sum + max(mx, a[pos])); return; } if(cnt + n - pos >= k) { rec(pos + 1, cnt, sum, max(mx, a[pos])); } if(cnt + 1 + n - pos >= k) { End[pos] = 1; rec(pos + 1, cnt + 1, sum + max(mx, a[pos]), mx = 0); End[pos] = 0; } } int main () { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n >> k; for(int i = 1; i <= n; ++i) { cin >> a[i]; } End[n] = 1; rec(1, 0, 0, 0); cout << ans; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...