Submission #924565

#TimeUsernameProblemLanguageResultExecution timeMemory
924565boris_mihovFinancial Report (JOI21_financial)C++17
14 / 100
4035 ms7004 KiB
#include <algorithm> #include <iostream> #include <numeric> #include <cassert> #include <vector> #include <queue> #include <cmath> #include <set> typedef long long llong; const int MAXN = 300000 + 10; const int INF = 1e9; int n, d; int a[MAXN]; int dp[MAXN]; int perm[MAXN]; bool bigger[MAXN]; void solve() { std::iota(perm + 1, perm + 1 + n, 1); std::sort(perm + 1, perm + 1 + n, [&](int x, int y) { return a[x] > a[y] || (a[x] == a[y] && x < y); }); int res = 0; for (int i = 1 ; i <= n ; ++i) { int len = 0; for (int j = perm[i] + 1 ; j <= n ; ++j) { len += bigger[j]; if (len > d) { break; } if (bigger[j]) { dp[perm[i]] = std::max(dp[perm[i]], dp[j]); } } dp[perm[i]]++; bigger[perm[i]] = true; res = std::max(res, dp[perm[i]]); } std::cout << res << '\n'; } void input() { std::cin >> n >> d; for (int i = 1 ; i <= n ; ++i) { std::cin >> a[i]; } } void fastIOI() { std::ios_base :: sync_with_stdio(0); std::cout.tie(nullptr); std::cin.tie(nullptr); } int main() { fastIOI(); input(); solve(); 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...