hkshakib Jun 3rd, 2020 1,540 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5.     int n,k;
  6.     cin>>n>>k;
  7.     set<int>st;/// For storing value and auto sorting. Set is using for storing unique value;
  8.     int cnt=0; /// Storing result
  9.     for(int i=1;i<=n;i++)
  10.     {
  11.         int a;
  12.         cin>>a;
  13.         if(st.size()==k)/// If size of set is equal k that means we can check min value and delete remaining elements.
  14.         {
  15.             cnt++;
  16.             int p = *st.begin();///Store first value of set. First value is the min value. because set is sorted by ascending automatically
  17.             st.clear();/// Then clear all elements;/
  18.             st.insert(p);/// Again insert min value for continue checking
  19.         }
  20.         st.insert(a);/// Insert new value of array
  21.     }
  22.     cout<<cnt+1<<endl;
  23. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand