hkshakib Jun 3rd, 2020 1,540 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- using namespace std;
- int main()
- int 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;
- if(st.size()==k)/// If size of set is equal k that means we can check min value and delete remaining elements.
- 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
RAW Paste Data