Submission #854798

# Submission time Handle Problem Language Result Execution time Memory
854798 2023-09-29T02:36:17 Z NeroZein K blocks (IZhO14_blocks) C++17
0 / 100
0 ms 600 KB
#include "bits/stdc++.h"
using namespace std;

#ifdef Nero
#include "Deb.h"
#else
#define deb(...)
#endif

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  vector<long long> dp(n); 
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
    dp[i] = max(dp[i - 1], (long long) a[i]); 
  }
  for (int j = 1; j < k; ++j) {
    stack<pair<int, long long>> stk; 
    for (int i = j; i < n; ++i) {
      while (!stk.empty() && stk.top().second <= a[i - 1]) {
        stk.pop(); 
      }
      if (stk.empty() || (stk.top().first + stk.top().second > a[i - 1] + dp[i - 1])) {
        stk.push({a[i - 1], dp[i - 1]});
      }
      dp[i] = stk.top().first + stk.top().second; 
    }
  }
  cout << dp[n - 1] << '\n'; 
  return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 600 KB Output isn't correct
2 Halted 0 ms 0 KB -