Submission #74305893


Source Code Expand

#include <bits/stdc++.h>
#define ll long long
const ll N = 1e6 + 5, MOD = 1e9 + 7, inf = 2e18;
using namespace std;
int dx[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dy[] = {1, -1, 0, 0, 1, -1, 1, -1};
char di[] = {'R', 'L', 'D', 'U'};
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T>
using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;

void Ebraam() {
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
#ifndef ONLINE_JUDGE
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        v[i] %= k;
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    ll ans = 0;
    for (int i = 0; i < n - 1; i++) {
        ans = max(ans, v[i + 1] - v[i]);
    }
    cout << k - max(ans, k - v.back() + v.front());
}

int main() {
    Ebraam();
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
        if (t)cout << endl;
    }
    return 0;
}

Submission Info

Submission Time
Task D - Minimize Range
User Ebraam_Yousef
Language C++23 (GCC 15.2.0)
Score 400
Code Size 1347 Byte
Status AC
Exec Time 20 ms
Memory 4932 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 2
AC × 44
Set Name Test Cases
Sample 00_sample_01.txt, 00_sample_02.txt
All 00_sample_01.txt, 00_sample_02.txt, 01_01.txt, 01_02.txt, 01_03.txt, 01_04.txt, 01_05.txt, 01_06.txt, 01_07.txt, 01_08.txt, 01_09.txt, 01_10.txt, 01_11.txt, 01_12.txt, 01_13.txt, 01_14.txt, 01_15.txt, 01_16.txt, 01_17.txt, 01_18.txt, 01_19.txt, 01_20.txt, 02_01.txt, 02_02.txt, 02_03.txt, 02_04.txt, 02_05.txt, 02_06.txt, 02_07.txt, 02_08.txt, 02_09.txt, 02_10.txt, 02_11.txt, 02_12.txt, 03_01.txt, 03_02.txt, 03_03.txt, 03_04.txt, 03_05.txt, 03_06.txt, 03_07.txt, 03_08.txt, 03_09.txt, 03_10.txt
Case Name Status Exec Time Memory
00_sample_01.txt AC 1 ms 3532 KiB
00_sample_02.txt AC 1 ms 3592 KiB
01_01.txt AC 10 ms 4184 KiB
01_02.txt AC 11 ms 4104 KiB
01_03.txt AC 17 ms 4604 KiB
01_04.txt AC 10 ms 3920 KiB
01_05.txt AC 7 ms 3800 KiB
01_06.txt AC 5 ms 3656 KiB
01_07.txt AC 3 ms 3688 KiB
01_08.txt AC 4 ms 3708 KiB
01_09.txt AC 14 ms 4316 KiB
01_10.txt AC 3 ms 3564 KiB
01_11.txt AC 6 ms 3712 KiB
01_12.txt AC 10 ms 4036 KiB
01_13.txt AC 4 ms 3704 KiB
01_14.txt AC 8 ms 3872 KiB
01_15.txt AC 6 ms 3748 KiB
01_16.txt AC 1 ms 3700 KiB
01_17.txt AC 14 ms 4368 KiB
01_18.txt AC 13 ms 4292 KiB
01_19.txt AC 18 ms 4824 KiB
01_20.txt AC 13 ms 4316 KiB
02_01.txt AC 1 ms 3480 KiB
02_02.txt AC 1 ms 3404 KiB
02_03.txt AC 1 ms 3480 KiB
02_04.txt AC 1 ms 3480 KiB
02_05.txt AC 1 ms 3560 KiB
02_06.txt AC 1 ms 3600 KiB
02_07.txt AC 7 ms 4896 KiB
02_08.txt AC 10 ms 4816 KiB
02_09.txt AC 10 ms 4876 KiB
02_10.txt AC 7 ms 4900 KiB
02_11.txt AC 10 ms 4788 KiB
02_12.txt AC 20 ms 4900 KiB
03_01.txt AC 19 ms 4776 KiB
03_02.txt AC 20 ms 4932 KiB
03_03.txt AC 19 ms 4896 KiB
03_04.txt AC 20 ms 4776 KiB
03_05.txt AC 20 ms 4816 KiB
03_06.txt AC 20 ms 4828 KiB
03_07.txt AC 20 ms 4876 KiB
03_08.txt AC 20 ms 4924 KiB
03_09.txt AC 19 ms 4900 KiB
03_10.txt AC 19 ms 4864 KiB