Submission #1138516

#TimeUsernameProblemLanguageResultExecution timeMemory
1138516ByeWorldRoom Temperature (JOI24_ho_t1)C++20
15 / 100
2 ms584 KiB
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define pb push_back
#define fi first
#define se second
#define lf (id<<1)
#define rg ((id<<1)|1)
#define md ((l+r)>>1)
#define ld long double
using namespace std;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<int,pii> ipii;
typedef pair<pii,pii> ipiii;
const int MAXN = 5e5+50;
const int SQRT = 610;
const int MAXA = 50;
const int MOD = 998244353;
const int LOG = 21;
const int INF = 1e18;
const ld EPS = 1e-12;

int n, m, a[MAXN];

signed main(){
    // ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1; i<=n; i++) cin >> a[i];
    sort(a+1, a+n+1);
    for(int i=1; i<n; i++){
        int dis = (a[n]-a[1])/m;
        a[i] += dis*m;
    }
    int ans = INF;
    set <int> s;
    for(int i=1; i<=n; i++) s.insert(a[i]);
    for(int i=1; i<=n; i++){
        int val = *(--s.end()) - *s.begin();
        ans = min(ans, (val+1)/2);
        int p = *(s.begin());
        s.erase(p); s.insert(p+m);
    }
    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...