제출 #895140

#제출 시각아이디문제언어결과실행 시간메모리
895140d4xnRabbit Carrot (LMIO19_triusis)C++17
14 / 100
1047 ms848 KiB
#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];
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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...