Untitled
Anonymous
c_cpp
02/21/2026 7:22 PM
572 B
27
Indexable
#include <bits/stdc++.h>
using namespace std;
// Time Complexity: O(n log n)
// Memory Complexity: O(n)
using ll = long long;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n; cin >> n;
vector<int> a(n);
for(auto &x : a) cin >> x;
map<int, int> dp;
int ans = 0;
for(int i = 0; i < n; i++) {
dp[a[i]] = max(dp[a[i]], dp[a[i]-1]+1);
ans = max(ans, dp[a[i]]);
}
cout << ans << "\n";
return 0;
}Editor is loading...
Leave a Comment