#include<bits/stdc++.h>
using namespace std;
using i64 = long long;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n,t;
cin >> n >> t;
vector<int> a(n);
for(int i = 0;i < n;i++){
cin >> a[i];
a[i] %= t;
}
sort(a.begin(),a.end());
int ans = t - 1;
for(int i = 0;i < n - 1;i++){
// if ith is left point
int s = a[i];
int e = t - 1;
while(e > s){
int mid = (s + e + 1) / 2;
int k = (t - (mid - a[i]));
int ba = mid - k;
bool ok = a[i + 1] >= ba;
if(ok){
s = mid;
}else{
e = mid - 1;
}
}
ans = min(ans,(t - (e - a[i])));
}
for(int i = 1;i < n;i++){
// if ith is right point
int s = 0;
int e = a[i];
while(e > s){
int mid = (s + e) / 2;
int k = (t - (a[i] - mid));
int ba = (mid + k) % t;
bool ok = a[i - 1] <= ba;
if(ok){
e = mid;
}else{
s = mid + 1;
}
}
ans = min(ans,(t - (a[i] - s)));
}
cout << ans << '\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... |