Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define TEMP int
#define ordered_set                                                            \\
  tree<TEMP, null_type, less<TEMP>, rb_tree_tag,                               \\
       tree_order_statistics_node_update>
auto clk = clock();

ll mexp(ll a, ll b, ll m) {
  ll ans = 1;
  a %= m;
  while (b) {
    if (b & 1)
      ans = ans * a % m;
    b >>= 1;
    a = a * a % m;
  }
  return ans;
}

const int N = 400005;

ll a[N];

int main() {
  IOS srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int k, n;
  cin >> k >> n;
  FOR(i, 1, n) { cin >> a[i]; }
  FOR(i, n + 1, 2 * n) { a[i] = k + a[i - n]; }
  ll ans = 1e18;
  FOR(i, n, 2 * n) { ans = min(ans, a[i] - a[i - n + 1]); }
  cout << ans;

  cerr << endl
       << endl
       << "Time: " << fixed << setprecision(12)
       << (long double)(clock() - clk) / CLOCKS_PER_SEC << " ms" << endl
       << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define IOS                                                                    \\
  ios_base::sync_with_stdio(0);                                                \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define MOD 1000000007
#define MOD2 998244353
#define pb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(x) (ll) x.size()
#define F first
#define S second
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define ROF(i, a, b) for (ll i = a; i >= b; --i)
#define trace(x) cerr << #x << ": " << x << '\\n';
typedef long long ll;
using namespace std;
using namespace __gnu_pbds;
#define TEMP int
#define ordered_set                                                            \\
  tree<TEMP, null_type, less<TEMP>, rb_tree_tag,                               \\
       tree_order_statistics_node_update>
auto clk = clock();

ll mexp(ll a, ll b, ll m) {
  ll ans = 1;
  a %= m;
  while (b) {
    if (b & 1)
      ans = ans * a % m;
    b >>= 1;
    a = a * a % m;
  }
  return ans;
}

const int N = 200005;

ll a[N];

int main() {
  IOS srand(chrono::high_resolution_clock::now().time_since_epoch().count());

  int k, n;
  cin >> k >> n;
  FOR(i, 1, n) { cin >> a[i]; }
  FOR(i, n + 1, 2 * n) { a[i] = k + a[i - n]; }
  ll ans = 1e18;
  FOR(i, n, 2 * n) { ans = min(ans, a[i] - a[i - n + 1]); }
  cout << ans;

  cerr << endl
       << endl
       << "Time: " << fixed << setprecision(12)
       << (long double)(clock() - clk) / CLOCKS_PER_SEC << " ms" << endl
       << endl;

  return 0;
}