Untitled
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; // Multiset with less_equal typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; void PPPPPP() { ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(0); #ifndef ONLINE_JUDGE freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif } #define int long long const int mod = 1e9 + 7; long long power(int x, int y, int p) { int result = 1; x = x % p; while (y > 0) { if (y & 1) result = (result * x) % p; y = y >> 1; x = (x * x) % p; } return result; } int mod_inverse(int a, int p) { return power(a, p - 2, p); } #define all(a) a.begin(), a.end() int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, 1, - 1}; signed main() { PPPPPP(); int t = 1; // cin >> t; Z: while (t--) { int n, k; cin >> n >> k; string s; cin >> s; int pre[26][n + 1]; memset(pre, 0 , sizeof pre); for (int i = 0; i < n; i++){ pre[s[i]- 'a'][i + 1] = 1; } for (int i = 0; i < 26; i++) for (int j = 1; j <= n; j++) pre[i][j] += pre[i][j - 1]; int ans = 0; for (int i = 0; i + k <= n; i++){ int cur = 0; for(auto ch = 'a'; ch <= 'z'; ch++){ if (pre[ch - 'a'][i + k] - pre[ch - 'a'][i]) cur++; } ans = max(ans, cur); } cout << ans; } }
Leave a Comment