#include using namespace std; #define int long long #define all(x) x.begin(), x.end() #define app push_back #ifdef LOCAL #define debug(...) [](auto...a){ ((cout << a << ' '), ...) << '\n';}(#__VA_ARGS__, ":", __VA_ARGS__) #else #define debug(...) #endif const int inf=1e18; const int maxn=2e5+5; vector inter[maxn]; int32_t main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); int n,k,l,u;cin>>n>>k>>l>>u; int a[n];for(int i=0;i>a[i]; sort(a,a+n); int low=(-inf);int up=inf; while(up-low>1) { int mid=(low+up)/2; int c1=0,c2=0; for(int i=0;i=u-k+1) {++c2;} else if(a[i]+mid<=l-1) {++c1;} } if(c2>=c1) up=mid; else low=mid; } auto f=[&](int x)->int { if(xu) {return (x-u+k-1)/k;} }; int x=up; for(int i=0;i