bolo17

Untitled

Aug 29th, 2020
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.44 KB | None | 0 0
  1. / C++ includes used for precompiling -*- C++ -*-
  2.     2
  3.     3 // Copyright (C) 2003-2013 Free Software Foundation, Inc.
  4.     4 //
  5.     5 // This file is part of the GNU ISO C++ Library.  This library is free
  6.     6 // software; you can redistribute it and/or modify it under the
  7.     7 // terms of the GNU General Public License as published by the
  8.     8 // Free Software Foundation; either version 3, or (at your option)
  9.     9 // any later version.
  10. #include <bits/stdc++.h>
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15.     map<int, int>m;
  16.     int n, k;
  17.     cin>>n>>k;
  18.     int a[n];
  19.     for(int i = 0; i < n; i++){
  20.         cin>>a[i];
  21.     }
  22.     for(int i = 0; i < k; i++){
  23.         m[a[i]]++;
  24.     }
  25.     int l = 0, r = k - 1;
  26.     while(r < n){
  27.         cout<<m.begin()->first<<" ";
  28.         r++;
  29.         m[a[r]]++;
  30.         m[a[l]]--;
  31.         if(m[a[l]] == 0){
  32.             m.erase(a[l]);
  33.         }
  34.         l++;
  35.     }
  36. }
  37.  
  38. RAW Paste Data
  39.  
  40. #include <bits/stdc++.h>
  41. using namespace std;
  42.  
  43. int main()
  44. {
  45.     map<int, int>m;
  46.     int n, k;
  47.     cin>>n>>k;
  48.     int a[n];
  49.     for(int i = 0; i < n; i++){
  50.         cin>>a[i];
  51.     }
  52.     for(int i = 0; i < k; i++){
  53.         m[a[i]]++;
  54.     }
  55.     int l = 0, r = k - 1;
  56.     while(r < n){
  57.         cout<<m.begin()->first<<" ";
  58.         r++;
  59.         m[a[r]]++;
  60.         m[a[l]]--;
  61.         if(m[a[l]] == 0){
  62.             m.erase(a[l]);
  63.         }
  64.         l++;
  65.     }
  66. }
  67.  
  68. Get link:https://ouo.io/xErMIY
Add Comment
Please, Sign In to add comment