#include<bits/stdc++.h>
#define ll long long
#define ldb long double
#define db double
#define fi first
#define se second
#define sza(a) (int)a.size()
#define pir pair<int,int>
#define pirll pair<ll,ll>
using namespace std;
const int maxn = 5e5 + 5;
template <class t1,class t2> inline void maxi(t1 &x,t2 y){if (x < y) x = y;}
template <class t1,class t2> inline void mini(t1 &x,t2 y){if (x > y) x = y;}
multiset <int> s;
vector <int> lst;
void input(int n,int T){
for (int i = 1 ; i <= n ; i++){
int x;
cin >> x;
s.insert(x % T);
if (x >= T) lst.push_back(x % T);
}
}
int get_dist(){
if (s.size() < 2) return 0;
return ((*s.rbegin()) - (*s.begin()) + 1)/2;
}
int solve(int n,int T){
int res = get_dist();
sort(lst.begin(),lst.end());
for (int x : lst){
s.erase(s.lower_bound(x));
s.insert(x + T);
mini(res,get_dist());
}
return res;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int n,T;
cin >> n >> T;
input(n,T);
cout << solve(n,T) << "\n";
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... |