Submission #805650

#TimeUsernameProblemLanguageResultExecution timeMemory
805650myst6Financial Report (JOI21_financial)C++14
60 / 100
4051 ms7540 KiB
#include <bits/stdc++.h> using namespace std; int main() { cin.tie(0)->sync_with_stdio(0); int n, d; cin >> n >> d; vector<int> A(n); for (int i=0; i<n; i++) cin >> A[i]; if (d == 1) { stack<int> s; int ans = 0; for (int i=n-1; i>=0; i--) { while (!s.empty() && s.top() <= A[i]) s.pop(); s.push(A[i]); ans = max(ans, (int)s.size()); } cout << ans << "\n"; } else { vector<int> dp(n,1); int ans = 0; for (int i=0; i<n; i++) { vector<int> minpath(n); multiset<int> path; for (int j=max(0,i-d); j<i; j++) { if (A[j] < A[i]) dp[i] = max(dp[i], dp[j]+1); if (A[j] == A[i]) dp[i] = max(dp[i], dp[j]); minpath[j] = A[j]; path.insert(A[j]); } for (int j=i-d-1; j>=0; j--) { minpath[j] = max(*path.begin(), A[j]); if (A[j] >= minpath[j]) { if (A[j] < A[i]) dp[i] = max(dp[i], dp[j]+1); if (A[j] == A[i]) dp[i] = max(dp[i], dp[j]); } path.erase(path.find(minpath[j+d])); path.insert(minpath[j]); } ans = max(ans, dp[i]); } cout << ans << "\n"; } return 0; }
#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...