#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double db;
#define int ll
#define all(x) (x).begin(), (x).end()
#define md ((tl + tr) >> 1)
#define TL v + v, tl, md
#define TR v + v + 1, md + 1, tr
#define Tl t[v].l, tl, md
#define Tr t[v].r, md + 1, tr
constexpr int maxn = 200'007;
constexpr ll inf = 1e18 + 7;
constexpr ll M = 998244353;
int binpow(int a, int n) {
if (n == 0)
return 1;
if (n & 1)
return a * binpow(a, n - 1) % M;
int x = binpow(a, n >> 1);
return x * x % M;
}
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, 1, 0, -1};
const db eps = 0.000000000000001;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int random(int l, int r) {
return uniform_int_distribution<int>(l, r)(rng);
}
int n, t, a[maxn];
int calc(int x, int y) {
if (x >= y)
return x - y;
return x + t - y;
}
void solve() {
cin >> n >> t;
set<int> s;
for (int i = 0; i < n; i++) {
cin >> a[i];
s.insert(a[i] % t);
}
n = 0;
for (auto now : s) {
a[n] = now;
n++;
}
int mx = 0;
for (int i = 0; i < n; i++) {
mx = max(mx, calc(a[(i + 1) % n], a[i]));
}
cout << (t - mx + 1) / 2;
}
signed main() {
// freopen("qi.in", "r", stdin);
// freopen("qi.out", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int test = 1;
// cin >> test;
while (test--) {
solve();
// cout << '\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... |