Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- int main(){
- int n, k;
- cin >> n >> k;
- int niza[n];
- for(int i = 0; i < n; i++) {
- cin >> niza[i];
- }
- vector<int> cnt(100005, 0);
- int sum = 0;
- int unique = 0;
- for(int i = 0; i < k; i++) {
- sum += niza[i];
- cnt[niza[i]]++;
- if(cnt[niza[i]] == 1) {
- unique++;
- }
- }
- cout << unique << " " ;
- int res = 0;
- if(unique == k) {
- res = max(res, sum);
- }
- for(int i = k; i < n; i++) {
- sum -= niza[i - k];
- sum += niza[i];
- cnt[niza[i - k]]--;
- if(cnt[niza[i - k]] == 0) {
- unique--;
- }
- cnt[niza[i]]++;
- if(cnt[niza[i]] == 1) {
- unique++;
- }
- cout << unique << " ";
- if(unique == k) {
- res = max(res, sum);
- }
- }
- cout << endl;
- cout << res << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement