This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#include<unordered_map>
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
#define rrep(i,a,b) for(int i=int(a);i>int(b);i--)
#define trav(a,v) for(auto& a: v)
#define sz(v) v.size()
#define all(v) v.begin(),v.end()
#define vi vector<int>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const long long inf = 1e15;
using namespace std;
int main() {
cin.sync_with_stdio(false);
int n, d;
cin >> n >> d;
vector<pair<ll, int>> v(n);
rep(i, 0, n) {
cin >> v[i].first;
v[i].second = -i;
}
sort(all(v));
vector<ll> dp(n, -inf);
rep(i, 0, n) {
dp[-v[i].second] = 1;
ll cur = d;
rrep(j, -v[i].second - 1,-1) {
dp[-v[i].second] = max(dp[-v[i].second], dp[j] + 1);
if (dp[j] != -inf)cur = d;
else if (!--cur)break;
}
}
ll ans = 1;
trav(a, dp)ans = max(ans, a);
cout << ans << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |