Skip to content

Instantly share code, notes, and snippets.

@theortsac
Last active September 6, 2023 14:03
Show Gist options
  • Save theortsac/6ee8f33b5ab02614eba71cd129fdc54f to your computer and use it in GitHub Desktop.
Save theortsac/6ee8f33b5ab02614eba71cd129fdc54f to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, s, j;
cin >> n >> s;
vector<int> u(s+1);
int d = 0, ans = 0;
for (int i = 1; i <= n; i++) {
cin >> j;
if (u[j] >= (i - d)) {
d -= (u[j] - (i - d) + 1);
}
d++;
u[j] = i;
ans = max(ans, d);
}
cout << ans << "\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment