Submission #1243870

#TimeUsernameProblemLanguageResultExecution timeMemory
1243870TobFinancial Report (JOI21_financial)C++20
48 / 100
4094 ms3912 KiB
#include <bits/stdc++.h>

#define F first
#define S second
#define all(x) x.begin(), x.end()
#define pb push_back
#define FIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair <ll, ll> pii;

const int N = 3e5 + 7;

int n, d;
int a[N], f[N], ia[N];

int main () {
	FIO;
	cin >> n >> d;
	
	for (int i = 0; i < n; i++) cin >> a[i], ia[i] = i;
	sort(ia, ia+n, [&](int x, int y){return a[x] < a[y];});
	
	for (int i = 0; i < n; i++) {
		int x = ia[i];
		int str = 0;
		f[x] = 1;
		for (int j = x-1; j >= 0 && str < d; j--) {
			if (a[j] >= a[x]) str++;
			else str = 0, f[x] = max(f[x], f[j]+1);
		}
	}
	
	int mx = 0;
	for (int i = 0; i < n; i++) mx = max(mx, f[i]);
	
	cout << mx;

	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...