#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,min(abs(v[i]-sr)%t,abs(t-abs(v[i]-sr)%t)));
}
return s;
}
void solve() {
ll n;
cin >> n >> t;
v.resize(n);
for (ll i = 0; i < n; i++) {
cin >> v[i];
}
ll l=0,r=1e9;
// ll poprzedni = how_much((l+r+1)/2+1);
ll essa = how_much(0);
for (ll i = 1; i <= t; i++) {
ll sigma = how_much(i);
// if(sigma>=essa){
// cout << essa << endl;
// return ;
// }
essa=min(essa,sigma);
}
cout << essa << endl;
// cout << endl;
// while(l<r){
// int sr = (l+r)/2;
// ll wynik = how_much(sr);
// if(wynik<=poprzedni) r = sr;
// else l = sr+1;
// }
// 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... |