#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 vec; //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}); //vec.push_back({{a[i], i}, 0}); //vec.push_back({{b[i], i}, 1}); //time.push_back(b[i]); } //sort(vec.begin(), vec.end()); queue que; int cnt=0; priority_queue, greater> pque; for(int i=0; ia[i]) break; cnt--; pque.pop(); if(!que.empty()){ int j=que.front(); que.pop(); a[j]=x; cnt++; pque.push(a[j]+b[j]); } } if(cnta[i]) break; cnt--; pque.pop(); if(!que.empty()){ int j=que.front(); que.pop(); a[j]=x; cnt++; pque.push(a[j]+b[j]); } } for(int i=0; i 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){ //v.push({{*upper_bound(time.begin(), time.end(), p.first.first), i}, t}); assert(0); continue; }else if(x2==n+1){ x=y2; }else if(y2==0){ x=x2; }else{ if(x2-max(k1, k2)>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); } } for(int i=0; i