Submission #895141

# Submission time Handle Problem Language Result Execution time Memory
895141 2023-12-29T13:27:15 Z d4xn Rabbit Carrot (LMIO19_triusis) C++17
0 / 100
1 ms 604 KB
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;

const int N = 2e5+1, inf = INT_MAX;

int n, m, mx, a[N];
unordered_map<int, int> dp[2];

signed main() {
  ios::sync_with_stdio(false); cin.tie(nullptr);

  cin >> n >> m;
  a[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }

  dp[0][0] = 0;
  for (int i = 1; i <= n; i++) {
    dp[i%2].clear();
    for (auto& [x, y] : dp[(i-1)%2]) {
      if (y+m >= a[i]) {
        auto it = dp[i%2].find(x);
        if (it == dp[i%2].end()) dp[i%2][x] = a[i];
        it->second = max(it->second, a[i]);
      }
      
      auto it = dp[i%2].find(x+1);
      if (it == dp[i%2].end()) dp[i%2][x+1] = y+m;
      it->second = max(it->second, y+m);
    }
  }

  cout << dp[n%2].begin()->first << "\n";
}
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 604 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -