Submission #1322646

#TimeUsernameProblemLanguageResultExecution timeMemory
1322646vaishakhvRoom Temperature (JOI24_ho_t1)C++20
0 / 100
2108 ms406964 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define eb emplace_back

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    ll n, t;
    cin >> n >> t;
    vector<ll> a(n);
    for (ll i{}; i < n; i++) cin >> a[i];
    
    set<ll> cands;
    
    ll mn = *min_element(a.begin(), a.end());
    ll mx = *max_element(a.begin(), a.end());
    
    for (ll i{}; i < n; i++) {
        ll max_k = (mx - mn) / t + 10;
        for (ll k{}; k <= max_k; k++) {
            cands.insert(a[i] - k * t);
        }
    }
    
    ll ans = 1e18;
    for (ll x : cands) {
        ll unp = 0;
        for (ll i{}; i < n; i++) {
            ll dis;
            if (x >= a[i]) {
                dis = x - a[i];
            } else {
                ll k = (a[i] - x) / t;
                ll d1 = abs(x - (a[i] - k * t));
                ll d2 = abs(x - (a[i] - (k + 1) * t));
                dis = min(d1, d2);
            }
            unp = max(unp, dis);
        }
        ans = min(ans, unp);
    }
    
    cout << ans << "\n";
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...