Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- set<pair<int,int> >hi,;
- set<pair<int,int>,greater<pair<int,int> > >lo;
- void balance()
- {
- while(hi.size() > lo.size())
- {
- lo.insert(hi.begin());
- hi.erase(hi.begin());
- }
- while(lo.size()-1 > hi.size() )
- {
- hi.insert(lo.begin());
- lo.erase(lo.begin());
- }
- }
- int activityNotifications(vector<int> expenditure, int d) {
- for(int i=0;i<expenditure.size();i++)
- {
- lo.insert( make_pair(expenditure[i],i) );
- balance();
- if(i>=d)
- {
- auto it = lo.lower_bound( make_pair(expenditure[i-d],i-d) );
- if(it!=lo.end()) lo.erase(it);
- else {
- auto it = hi.lower_bound( make_pair(expenditure[i-d],i-d) );
- if(it!=hi.end()) hi.erase(it);
- }
- }
- balance();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement