//#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define f first
#define s second
#define all(x) x.begin(),x.end()
#define _ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int dx[4]={0,0,1,-1};
int dy[4]={1,-1,0,0};
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
const ll inf=(ll)1e18;
int main() {_
int n,q;
cin>>n>>q;
ll d,a,b;
cin>>d>>a>>b;
vector<ll> L(n+1),R(n+1);
L[0]=-1;
R[0]=-1;
for(int i=1;i<=n;i++){
cin>>L[i]>>R[i];
}
vector<pair<ll,ll>> no;
auto in=[&](ll x){
int pos=lower_bound(all(R),x)-R.begin();
if(pos<=n and L[pos]<=x) return true;
return false;
};
auto in2=[&](ll x){
int pos=upper_bound(all(no),make_pair(x,inf))-no.begin();
if(pos>0 and x<=no[pos-1].s) return true;
return false;
};
bool one=false;
if((a*d)<=b) one=true;
auto solve1=[&](){
vector<ll> pos(n+1,inf);
pos[0]=0;
vector<ll> sum(n+1);
ll bad=inf;
int prv=0;
for(int i=0;i<n;i++){
if((R[i+1]-L[i+1]+2)>d){
bad=L[i+1];
break;
}
if(pos[i]==inf) continue;
int l=lower_bound(all(R),pos[i]+d)-R.begin()-1;
int r=lower_bound(all(R),L[i+1]-1+d)-R.begin()-1;
if(l<n and pos[i]+d>=L[l+1]) l++;
l=max(l,prv+1);
l=max(l,i+1);
if(l<=r){
for(int j=l;j<=r;j++){
pos[j]=max(R[j]+1-d,pos[i])+d;
}
prv=r;
}
}
/*cout<<'\n';
for(int i=0;i<=n;i++){
cout<<pos[i]<<' '<<sum[i]<<'\n';
}
cout<<bad<<'\n';
cout<<'\n';*/
for(int i=0;i<q;i++){
ll x;
cin>>x;
if(in(x) or in2(x) or x>=bad){
cout<<-1<<'\n';
continue;
}
int id=upper_bound(all(L),x)-L.begin()-1;
if(x<pos[id]){
cout<<-1<<'\n';
continue;
}
ll ans=sum[id]+a*(x-pos[id]);
cout<<x<<'\n';
}
};
auto solve2=[&](){
};
if(one) solve1();
else solve2();
return 0;
}
//maybe its multiset not set
//yeeorz
//diaoborz
/*
3 1
4 1 4
4 5
10 12
14 14
13
5 10
10 1 10
7 11
25 32
37 38
43 44
50 52
6
12
18
24
30
36
42
48
54
60
10 10
10 1 10
8 9
15 19
24 32
39 41
45 46
52 58
60 65
74 83
89 97
100 101
69
48
86
86
15
60
61
52
55
67
*/
Compilation message (stderr)
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:15:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:16:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
16 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |