#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define popcount __builtin_popcount using namespace std; typedef long long int ll; typedef pair P; int main() { int n, k1, k2; cin>>n>>k1>>k2; //k1--; k2--; int q; cin>>q; int a[100010], b[100010]; using Pi=pair; priority_queue, greater> v; vector time; for(int i=0; i>a[i]>>b[i]; b[i]+=a[i]; v.push({{a[i], i}, 0}); v.push({{b[i], i}, 1}); time.push_back(b[i]); } sort(time.begin(), time.end()); time.erase(unique(time.begin(), time.end()), time.end()); set st1, st2; bool used[100010]={}; for(int i=0; i<=n+1; i++){ st1.insert(i); st2.insert(i); } queue myon; int ans[100010]; while(!v.empty()){ auto p=v.top(); v.pop(); int t=p.second; int i=p.first.second; if(t==0){ auto itr=st1.lower_bound(max(k1, k2)); int x=*itr; itr--; int y=*itr; if(x==n+1 && y==0){ auto itr2=st2.lower_bound(max(k1, k2)); int x2=*itr2; itr2--; int y2=*itr2; if(x2==n+1 && y2==0){ //auto r=v.top(); //cout<min(k1, k2)-y2){ x2=y2; }else if(k1min(k1, k2)-y){ x=y; }else if(k11) st1.erase(x-1); if(x0){ if(!used[x-1] && !used[x-2]) st1.insert(x-1); } if(x+1<=n){ if(!used[x+1] && !used[x+2]) st1.insert(x+1); } if(!used[x-1] && !used[x+1]) st1.insert(x); } } //cout<