Submission #37925

#TimeUsernameProblemLanguageResultExecution timeMemory
37925Just_Solve_The_ProblemK blocks (IZhO14_blocks)C++11
18 / 100
1000 ms5140 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long const int N = (int)1e5 + 7; int a[N]; ll ans = 1e14; int n, k; vector < int > dns; void go (int pos, int mx, ll sum = 0, int kk = 1, vector < int > vec = vector < int > ()) { mx = max(mx, a[pos]); if (pos == n + 1) { if (kk == k) { if (ans > sum + mx) { ans = sum + mx; dns = vec; } } return ; } if (kk + 1 <= k && pos != n) { vec.push_back(pos); go(pos + 1, 0, sum + mx, kk + 1, vec); vec.pop_back(); } go(pos + 1, mx, sum, kk, vec); } main() { scanf ("%d %d", &n, &k); for (int i = 1; i <= n; i++) { scanf ("%d", a + i); } go(1, 0); cout << ans << endl; // for (int to : dns) { // cout << to << ' ' ; // } }

Compilation message (stderr)

blocks.cpp:33:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
blocks.cpp: In function 'int main()':
blocks.cpp:34:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf ("%d %d", &n, &k);
                            ^
blocks.cpp:36:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf ("%d", a + i);
                            ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...