Submission #533151

#TimeUsernameProblemLanguageResultExecution timeMemory
5331514fectaFinancial Report (JOI21_financial)C++17
48 / 100
4075 ms14524 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define int ll #define ld long double #define pii pair<int, int> #define f first #define s second #define boost() cin.tie(0), cin.sync_with_stdio(0) const int MN = 300005; int n, d, a[MN], ans = 1, dp[MN], dead[MN], pos[MN]; vector<pii> v; bool cmp(pii p, pii q) { if (p.f != q.f) return p.f < q.f; return p.s > q.s; } int32_t main() { boost(); cin >> n >> d; for (int i = 1; i <= n; i++) cin >> a[i], v.push_back({a[i], i}); sort(v.begin(), v.end(), cmp); for (int i = 0; i < n; i++) pos[v[i].s] = i + 1; memset(dp, -0x3f, sizeof(dp)); memset(dead, 0x3f, sizeof(dead)); for (int i = 1; i <= n; i++) { dp[pos[i]] = 1, dead[pos[i]] = i; for (int j = 1; j <= n; j++) if (dead[j] < i - d) dp[j] = -0x3f3f3f3f, dead[j] = 0x3f3f3f3f; for (int j = 1; j < pos[i]; j++) dp[pos[i]] = max(dp[pos[i]], dp[j] + 1); for (int j = pos[i]; j <= n; j++) dead[j] = max(dead[j], i); ans = max(ans, dp[pos[i]]); } printf("%lld\n", ans); 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...