Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ll long long
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- int n, k;
- cin >> n >> k;
- vector<int>v(n);
- for (int i=0; i<n; i++) {
- cin >> v[i];
- }
- map<int,int>m;
- for (int i=0; i<k; i++) {
- m[v[i]]++;
- }
- // pair<int,int>x=*m.rbegin();
- // ll ans =x.first;
- int mx=0, x=0;
- for (auto [y,z]:m) {
- if (z>=mx) {
- mx=z;
- if (y>x) x=y;
- }
- }
- ll ans=x;
- for (int i=0; i<n-k; i++) {
- m[v[i]]--;
- m[v[i+k]]++;
- mx=0, x=0;
- for (auto [y,z]:m) {
- if (z>=mx) {
- mx=z;
- if (y>x) x=y;
- }
- }
- // pair<int,int>x=*m.rbegin();
- // ans+=x.first;
- ans+=x;
- }
- cout << ans << endl;
- return 0;
- }
- /*
- * multimap
- */
Advertisement
Add Comment
Please, Sign In to add comment