Submission #1301047

#TimeUsernameProblemLanguageResultExecution timeMemory
1301047sigmaligmaRoom Temperature (JOI24_ho_t1)C++20
35 / 100
2 ms584 KiB
#include <bits/stdc++.h>
using namespace std;

#define fastio                   \
    ios::sync_with_stdio(false); \
    cin.tie(nullptr);

#define s(x) x.size()
#define sort(x) sort(x.begin(), x.end())
#define rsort(x) sort(x.rbegin(), x.rend())
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define fi first
#define se second
#define INF 1e9
#define INFL 1e18

using ll = long long;
using pii = pair<ll, ll>;
vector<ll> v;
ll t;
ll how_much(ll sr)
{
    ll n = v.size();
    ll s = 0;
    for (ll i = 0; i < n; i++)
    {
        s = max(s, abs(sr - v[i]));
    }
    return s;
}
void solve()
{
    ll n;
    cin >> n >> t;
    v.resize(n);
    for (ll i = 0; i < n; i++)
    {
        cin >> v[i];
        v[i] %= t;
    }
    ll l = 0, r = 1e9;

    ll poprzedni = (l + r ) / 2 + 1;

    while (l < r)
    {
        int sr = (l + r) / 2;
        ll wynik = how_much(sr);
        if (wynik < poprzedni)
            r = sr;
        else
            l = sr + 1;
        poprzedni = wynik;
        // cout << l << ' ' << r << ' ' << sr << endl;
    }
    cout << how_much(l) << endl;
}

int main()
{
    fastio;
    int t = 1;
    // cin >> t;
    while (t--)
        solve();
    return 0;
}
#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...