제출 #736710

#제출 시각아이디문제언어결과실행 시간메모리
736710veehzFinancial Report (JOI21_financial)C++17
28 / 100
4096 ms1048576 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define pb push_back

int main() {
  int n, d;
  cin >> n >> d;
  vector<int> v(n);
  for (int i = 0; i < n; i++) cin >> v[i];
  do {
    // compression
    vector<int> dd = v;
    sort(dd.begin(), dd.end());
    dd.resize(unique(dd.begin(), dd.end()) - dd.begin());
    for (int i = 0; i < n; i++) {
      v[i] = lower_bound(dd.begin(), dd.end(), v[i]) - dd.begin();
    }
  } while (false);
  int mx = *max_element(v.begin(), v.end());

//   cout << mx << endl;
//   cout << "V: ";
//   for (auto x : v) cout << x << " ";
//   cout << endl;

  vector<vector<int>> dp(n, vector<int>(mx + 1, 0));
  vector<multiset<int>> cmax(mx + 1);

  for (int i = 0; i < n; i++) {
    // cout << "i=" << i << endl;
    int prev, cur = 0;
    for (int j = 0; j <= mx; j++) {
      prev = cur;

      if (cmax[j].size()) {
        // cout << " j=" << j << ' ' << *cmax[j].rbegin() << endl;
        cur = max(cur, *cmax[j].rbegin());
      }

      if (j < v[i]) continue;

      int candidate = max(cur, j ? dp[i][j - 1] : 0);
      if (v[i] == j) candidate = max(candidate, j ? prev + 1 : 1);
      dp[i][j] = candidate;
    }
    // cout << endl;

    if (i >= d) {
      for (int j = 0; j <= mx; j++) {
        cmax[j].erase(cmax[j].find(dp[i - d][j]));
      }
    }

    for (int j = 0; j <= mx; j++) {
      cmax[j].insert(dp[i][j]);
    }
  }

//   for (auto x : dp) {
//     for (auto y : x) cout << y << " ";
//     cout << endl;
//   }

  cout << *max_element(dp[n - 1].begin(), dp[n - 1].end()) << endl;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...