Advertisement
hkshakib

Untitled

Jun 3rd, 2020
1,958
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.79 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement