#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using str = string;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using vector2 = vector<vector<T>>;
template <class T>
using vector3 = vector<vector2<T>>;
#define sp ' '
#define nl '\n'
#define fi first
#define se second
#define size(a) ((int)(a).size())
#define all(a) begin(a), end(a)
#define tvl (tv * 2)
#define tvr (tv * 2 + 1)
#define FOR(i, l, r) for (int i = (l), _r = (r); i <= _r; i++)
#define FORD(i, r, l) for (int i = (r), _l = (l); i >= _l; i--)
#define FORIN(it, a) for (auto& it : a)
#define bmask(i) (1LL << (i))
#define bget(i, n) ((n) >> (i) & 1)
const int INF = 0x3f3f3f3f;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const ll MOD = 1e9 + 7;
void addm(ll& a, ll b) { a = (a + b % MOD) % MOD; }
void subm(ll& a, ll b) { a = (a + MOD - b % MOD) % MOD; }
void mulm(ll& a, ll b) { a = a * (b % MOD) % MOD; }
template <class T, class... C>
void minimize(T& a, C&&... v) {
a = min<T>({a, v...});
}
template <class T, class... C>
void maximize(T& a, C&&... v) {
a = max<T>({a, v...});
}
template <class T, class... C>
void assign(int n, const T& v, C&&... a) {
using e = int[];
e{(a.assign(n, v), 0)...};
}
template <class... C>
void resize(int n, C&&... a) {
using e = int[];
e{(a.resize(n), 0)...};
}
////////////////////////////////////////
template <class... T>
void print(T&&... a) {
cout << flush;
clog << "\n[debug] ";
using e = int[];
e{(clog << a << sp, 0)...};
clog << endl;
}
template <class Ch, class Tr, class C>
basic_ostream<Ch, Tr>& operator<<(basic_ostream<Ch, Tr>& cout, C a) {
cout << "{ ";
FORIN(it, a) cout << it << sp;
return cout << "}";
}
template <class T1, class T2>
ostream& operator<<(ostream& cout, pair<T1, T2> a) {
return cout << '(' << a.fi << sp << a.se << ')';
}
void logtime() {
print("[time]", clock() * 1.0 / CLOCKS_PER_SEC);
}
// JOI24_ho_t1
// <tags>
int n;
ll k;
vector<ll> a;
///////////////////////////////////////////////////////////////////////////////
namespace sub4 {
////////////////////////////////////////
ll calc(ll x) {
ll ans = 0;
FOR(i, 1, n) {
if (x >= a[i]) {
maximize(ans, x - a[i]);
} else {
ll y = a[i] - (a[i] - x) / k * k;
maximize(ans, min(y - x, x - (y - k)));
}
}
return ans;
}
////////////////////////////////////////
void main() {
ll ans = INFLL;
FOR(i, 0, 3000) minimize(ans, calc(i));
cout << ans;
}
bool run() {
return main(), 1;
}
}
////////////////////////////////////////////////////////////////////////////////
int main() {
#define TASK "JOI24_ho_t1"
// freopen(TASK".inp", "r", stdin);
// freopen(TASK".out", "w", stdout);
cin.tie(nullptr)->sync_with_stdio(false);
atexit(logtime);
////////////////////////////////////////
cin >> n >> k;
resize(n + 1, a);
FOR(i, 1, n) cin >> a[i];
sort(1 + all(a));
if (sub4::run()) return 0;
////////////////////////////////////////
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... |