Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <stack>
- using namespace std;
- bool comp(pair<int,int> p1, pair<int,int> p2){
- if(p1.first>=p2.first){
- return 0;
- }
- else{
- if(p1.second>=p2.second){
- return 0;
- }
- else{
- return 1;
- }
- }
- }
- int main(){
- int n;
- cin>>n;
- vector<pair<int,int>> a;
- for(int i=0;i<n;i++){
- int x,v;
- cin>>x>>v;
- a.push_back(make_pair(x,v));
- }
- sort(a.begin(),a.end(),comp);
- // for(auto i:a){
- // cout<<i.first<<" "<<i.second<<"\n";
- // }
- stack<int> st;
- vector<int> a1;
- for (int i=0;i<n;i++){
- int x=a[i].first, v=a[i].second;
- if (v==1){
- st.push(x);
- }
- else{
- if(!st.empty()){
- a1.push_back(x - st.top());
- st.pop();
- }
- }
- }
- sort(a1.begin(),a1.end());
- // for(auto i:a1){
- // cout<<i<<"\n";
- // }
- // map<int,int>
- // stack<pair<int,int>> st1;
- // for(int i=0;i<a.size();i++){
- // if(st.empty()){
- // st.push_back(a[i]);
- // continue;
- // }
- // if(st.top().second != a[i].second){
- //
- // }
- // }
- int m;
- cin>>m;
- for (int i=0;i<m;i++) {
- int time;cin>>time;
- cout<<(n-((upper_bound(a1.begin(),a1.end(),time*2)-a1.begin())*2))<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement