#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p)
{
return os << "(" << p.F << "," << p.S << ")";
}
template<typename T>
void print(const T &v, int lim = 1e9)
{
for(auto x : v)
if(lim-- > 0) cout << x << " ";
cout << "\n";
}
#define int long long
const int mxN = 5e5;
int N, T;
pair<int, int> stk[3 * mxN + 5];
int reg[mxN + 5];
int a[mxN + 5];
int brek = 0;
int id;
inline void push(int f, int s)
{
stk[brek].first = f;
stk[brek].second = s;
brek++;
}
signed main()
{
ios::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
cin >> N >> T;
for(int i = 0; i < N; i++) cin >> a[i];
auto check = [&](int mid)
{
brek = 0;
int cnt = 0;
for(int i = 0; i < N; i++)
{
for(int j = -1; j <= 1; j++)
{
int y = a[i] % T + j * T;
push(y - mid, -i - 1);
push(y + mid, i + 1);
}
}
int mx_cnt = 0;
sort(stk, stk + brek);
for(int i = 0; i < brek; i++)
{
id = stk[i].second;
// cout << l << " " << abs(id) - 1 << "\n";
if(id > 0)
{
if(id - 1 < 0) for(;;);
if(reg[id - 1] == 1) cnt--;
reg[id - 1]--;
}
else
{
if(-1 - id < 0) for(;;);
if(reg[-1 - id] == 0) cnt++;
reg[-1 - id]++;
}
// print(reg);
// cout << cnt << "\n";
if(mx_cnt < cnt) mx_cnt = cnt;
}
return mx_cnt == N;
};
int l = -1, r = 1e9;
//check(1);
//return 0;
while(l + 1 < r)
{
int mid = (l + r) / 2;
if(check(mid)) r = mid;
else l = mid;
}
cout << r << "\n";
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |