Submission #1211926

#TimeUsernameProblemLanguageResultExecution timeMemory
1211926pranjal__codingRoom Temperature (JOI24_ho_t1)C++20
35 / 100
1 ms328 KiB
#include<iostream>
#include<vector>

using namespace std;

int main() {
    int n, t;
    cin >> n >> t;
    vector<int> pref(n);
    int cold = 0;
    for (int i = 0; i < n; i++) {
        cin >> pref[i];
        if (pref[i] < pref[cold]) cold = i;
    }
    for (int i = 0; i < n; i++) {
        pref[i] = pref[i] - (t * ((pref[i] - cold) / t));
    }
    sort(pref.begin(), pref.end());
    cold = 0;
    int hot = n - 1;
    int best = pref[hot] - pref[cold];
    while (hot > 0) {
        pref[hot] -= t;
        if (pref[hot] < pref[cold]) cold = hot;
        hot--;
        best = max(best, pref[hot] - pref[cold]);
    }
    pref[hot] -= t;
    hot = pref[0];
    cold = pref[0];
    for (int i = 0; i < n; i++) {
        hot = max(hot, pref[i]);
        cold = min(cold, pref[i]);
    }
    best = min(best, hot - cold);
    cout << (best + 1) / 2 << 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...