Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n,k;
- cin>>n>>k;
- set<int>st;/// For storing value and auto sorting. Set is using for storing unique value;
- int cnt=0; /// Storing result
- for(int i=1;i<=n;i++)
- {
- int a;
- cin>>a;
- if(st.size()==k)/// If size of set is equal k that means we can check min value and delete remaining elements.
- {
- cnt++;
- int p = *st.begin();///Store first value of set. First value is the min value. because set is sorted by ascending automatically
- st.clear();/// Then clear all elements;/
- st.insert(p);/// Again insert min value for continue checking
- }
- st.insert(a);/// Insert new value of array
- }
- cout<<cnt+1<<endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement