#include <bits/stdc++.h>
using namespace std;
#define fastio \
ios::sync_with_stdio(false); \
cin.tie(nullptr);
#define s(x) x.size()
#define sort(x) sort(x.begin(), x.end())
#define rsort(x) sort(x.rbegin(), x.rend())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define INF 1e9
#define INFL 1e18
using ll = long long;
using pii = pair<ll, ll>;
vector<ll> v;
ll t;
ll how_much(ll sr)
{
ll n = v.size();
ll s = 0;
for (ll i = 0; i < n; i++)
{
s = max(s, abs(sr - v[i]));
}
return s;
}
void solve()
{
ll n;
cin >> n >> t;
v.resize(n);
for (ll i = 0; i < n; i++)
{
cin >> v[i];
ll wynik = abs(v[i]-t*1e9);
v[i] = min(v[i]%t,wynik%t);
}
ll l = 0, r = 1e9;
ll poprzedni = (l + r ) / 2 + 1;
// for (int i = 0; i < 10; i++) {
// cout << how_much(i) << ' ';
// }
// cout << endl;
// for (int i = 0; i < n; i++) {
// cout << v[i] << ' ';
// }
// cout << endl;
while (l < r)
{
int sr = (l + r) / 2;
ll wynik = how_much(sr);
if (wynik < poprzedni)
r = sr;
else
l = sr + 1;
poprzedni = wynik;
// cout << l << ' ' << r << ' ' << sr << endl;
}
cout << how_much(l) << endl;
}
int main()
{
fastio;
int t = 1;
// cin >> t;
while (t--)
solve();
return 0;
}
| # | 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... |