lina_os

Untitled

Apr 2nd, 2025
15
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  8. int n, k;
  9. cin >> n >> k;
  10. vector<int>v(n);
  11. for (int i=0; i<n; i++) {
  12. cin >> v[i];
  13. }
  14. map<int,int>m;
  15. for (int i=0; i<k; i++) {
  16. m[v[i]]++;
  17. }
  18. // pair<int,int>x=*m.rbegin();
  19. // ll ans =x.first;
  20. int mx=0, x=0;
  21. for (auto [y,z]:m) {
  22. if (z>=mx) {
  23. mx=z;
  24. if (y>x) x=y;
  25. }
  26. }
  27. ll ans=x;
  28. for (int i=0; i<n-k; i++) {
  29. m[v[i]]--;
  30. m[v[i+k]]++;
  31. mx=0, x=0;
  32. for (auto [y,z]:m) {
  33. if (z>=mx) {
  34. mx=z;
  35. if (y>x) x=y;
  36. }
  37. }
  38. // pair<int,int>x=*m.rbegin();
  39. // ans+=x.first;
  40. ans+=x;
  41. }
  42. cout << ans << endl;
  43. return 0;
  44. }
  45.  
  46. /*
  47. * multimap
  48. */
Advertisement
Add Comment
Please, Sign In to add comment