Submission #1242084

#TimeUsernameProblemLanguageResultExecution timeMemory
1242084nasjesRoom Temperature (JOI24_ho_t1)C++20
35 / 100
1 ms328 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll dim = 1e6+7;
//const ll mod = 1e9 + 7;
const ll inf = 1e18 + 77;
#define endl "\n"
#define fi first
#define pb push_back
#define se second
#define vll vector<ll>

ll n;
ll x;
ll a[dim];
ll check(ll md){
    ll mn1=0;
    for(int i=1; i<=n; i++){
        mn1=max(mn1, min(abs(x-a[i]-md)%x, abs(a[i]-md)%x));

    }
    return mn1;

}
int main() {
    cin>>n>>x;
    for(int i=1; i<=n; i++){
        cin>>a[i];
        a[i]=a[i]%x;
    }
    sort(a+1, a+1+n);
    ll mn1=0;
    ll mn2=0;
    ll ans=inf;
    ll l=0;
    ll r=x-1;
    while((r-l)>=3){
        ll m1=l+(r-l)/3;
        ll m2=r-(r-l)/3;
        if(check(m1)<check(m2)){
            r=m2-1;
        }
        else{
            l=m1;
        }
    }
    cout<<min({check(l), check(l+1), check(l+2), check(l+3)})<<endl;

    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...