Submission #768494

#TimeUsernameProblemLanguageResultExecution timeMemory
768494jmyszka2007Financial Report (JOI21_financial)C++17
0 / 100
4048 ms1768 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int LIM = 300'000;
int dp[LIM + 10];
int tab[LIM + 10];
int ran[LIM + 10];
int main() {
	int n, d;
	cin >> n >> d;
	for(int i = 1; i <= n; i++) {
		cin >> tab[i];
	}
	for(int i = 1; i <= n; i++) {
		int akt = i;
		for(int j = i + 1; j <= n; j++) {
			if(j - akt > d) {
				break;
			}
			if(tab[j] <= tab[i]) {
				akt = j;
			}
			ran[i] = j;
		}
	}
	for(int i = 1; i <= n; i++) {
		dp[i] = 1;
		for(int j = i - 1; j >= 1; j--) {
			if(tab[j] < tab[i] && ran[j] >= i) {
				dp[i] = max(dp[i], dp[j] + 1);
			}
		}
	}
	int ans = 0;
	for(int j = 1; j <= n; j++) {
		if(ran[j] == n && tab[j] >= tab[n]) {
			ans = max(ans, dp[j]);
		}
	}
	cout << ans << '\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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...