alexjercan/bugnet huggingface dataset:
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define fo(i, N) for (i = 0; i < N; ++i)
#define fos(i, b, N) for (i = b; i < N; ++i)
#define forr(i, N) for (i = N - 1; i >= 0; --i)
#define disp(n) cout << n << endl;
#define M 10000007
#define ll long long
#define vll vector<long long int>
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x > y ? x : y)
using namespace std;
int main() {
  long a, n;
  cin >> a >> n;
  long N[n], max = 0;
  int i;
  for (i = 0; i < n; ++i)
    cin >> N[i];
  for (i = 1; i < n; ++i) {
    if (N[i] - N[i - 1] > max)
      max = N[i] - N[i - 1];
  }
  if (a - N[n - 1] + N[0] > max)
    max = a - N[n - 1] + N[0];
  cout << a - max;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define fo(i, N) for (i = 0; i < N; ++i)
#define fos(i, b, N) for (i = b; i < N; ++i)
#define forr(i, N) for (i = N - 1; i >= 0; --i)
#define disp(n) cout << n << endl;
#define M 10000007
#define ll long long
#define vll vector<long long int>
#define min(x, y) (x < y ? x : y)
#define max(x, y) (x > y ? x : y)
using namespace std;
int main() {
  long a, n;
  cin >> a >> n;
  long N[1000], max = 0;
  int i;
  for (i = 0; i < n; ++i)
    cin >> N[i];
  for (i = 1; i < n; ++i) {
    if (N[i] - N[i - 1] > max)
      max = N[i] - N[i - 1];
  }
  if (a - N[n - 1] + N[0] > max)
    max = a - N[n - 1] + N[0];
  cout << a - max;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
using LL = long long;
const int INF = 0x3f3f3f3f;
const int N = 400005;
LL a[N];
LL sum[N];
int main() {
  LL k, n;
  scanf("%lld%lld", &k, &n);

  LL res = INF;
  for (int i = 1; i <= n; ++i) {
    scanf("%lld", &a[i]);
    a[n + i] = a[i] + k;
  }

  // for (int i = 1; i <= 2 * n; ++i) sum[i] = sum[i - 1] + a[i];

  for (int i = 1; i + n - 1 <= 2 * n; ++i) {
    res = min(res, a[i + n - 1] - a[i]);
  }

  printf("%lld\\n", res);

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm> //everybody dies in their nightmares
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define f(i, a, b) for (register int i = a; i <= b; ++i)
#define ff(i, a, b) for (register int i = a; i >= b; --i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const ll mod = 1e18 + 7;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) {
  ll res = x;
  f(i, 2, x / i) {
    if (x % i == 0) {
      res = res / i * (i - 1);
      while (x % i == 0)
        x /= i;
    }
  }
  if (x > 1)
    res = res / x * (x - 1);
  return res;
}
ll quickmod(ll a, ll n, ll m) {
  ll s = 1;
  while (n) {
    if (n & 1) {
      s = s * a % m;
    }
    a = (a * a) % m;
    n = n / 2;
  }
  return s;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) {
  if (!b) {
    d = a, x = 1, y = 0;
  } else {
    ex_gcd(b, a % b, y, x, d);
    y -= x * (a / b);
  }
}
ll inv(ll t, ll p) {
  ll d, x, y;
  ex_gcd(t, p, x, y, d);
  return d == 1 ? (x % p + p) % p : -1;
}
bool isPrime(ll x) {
  if (x == 2)
    return true;
  if (x % 2 == 0)
    return false;
  for (ll i = 2; i * i <= x; i++)
    if (x % i == 0)
      return false;
  return true;
}
// double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const int N = 2e5 + 5;
int t;
ll a[N];
int main() {
  int n, k;
  while (scanf("%d%d", &k, &n)) {
    ll ans = 0;
    f(i, 1, n) scanf("%lld", &a[i]);
    f(i, 3, n - 1) ans += a[i] - a[i - 1];
    ll mi = 2e9;
    ll p = a[1] + k - a[n];
    ll pp = a[2] - a[1];
    ll kk = a[n] - a[n - 1];
    mi = min(mi, p + kk);
    mi = min(mi, pp + kk);
    mi = min(mi, p + pp);
    ans += mi;
    cout << ans << endl;
  }
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int K, N;
  cin >> K >> N;
  int A[N], dif, max;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  max = (K - A[N - 1]) + A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] - A[i - 1] > max) {
      max = A[i] - A[i - 1];
    }
  }
  cout << K - max << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main() {
  int K, N;
  int A[10], dif, max;
  cin >> K >> N;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  max = (K - A[N - 1]) + A[0];
  for (int i = 0; i < N; i++) {
    if (A[i + 1] - A[i] > max) {
      max = A[i + 1] - A[i];
    }
  }
  cout << K - max << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int k, n;
  int a[200000];
  int distall = 0;
  int max = 0;

  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    if (a[i + 1] - a[i] > max) {
      max = a[i + 1] - a[i];
    }
  }
  if (k - a[n - 1] + a[0] > max) {
    max = k - a[n - 1] + a[0];
  }

  cout << k - max << endl;

  return 0;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <string>
using namespace std;

int main() {
  int k, n;
  int a[200000];
  int dist[200001];
  int distall = 0;

  cin >> k >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  for (int i = 0; i < n - 1; i++) {
    dist[i] = a[i + 1] - a[i];
  }
  dist[n - 1] = k - a[n - 1] + a[0];

  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (dist[i] < dist[j]) {
        int tmp = dist[i];
        dist[i] = dist[j];
        dist[j] = tmp;
      }
    }
  }

  for (int i = 1; i < n; i++) {
    distall += dist[i];
  }

  cout << distall << endl;

  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  a = K + A.at(0) - A.at(N - 1);
  for (int i = 0; i < N - 1; i++) {
    if (A.at(i + 1) - A.at(i) > a) {
      a = A.at(i + 1) - A.at(i);
    }
  }
  cout << K - a << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }
  a = K + A.at(0) - A.at(N - 1);
  for (int i = 0; i < N; i++) {
    if (A.at(i + 1) - A.at(i) > a) {
      a = A.at(i + 1) - A.at(i);
    }
  }
  cout << K - a << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "r", stdin);
  //	freopen("output.txt", "w", stdout);
  // #endif
}

int main() {
  c_p_c();
  int k, m;
  cin >> k >> m;
  int a[m];
  fo(i, m) cin >> a[i];
  int ans = a[m - 1] - a[0];
  Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
  cout << ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << " " << x << endl;
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define ll long long
#define pb push_back
#define endl "\\n"
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007

void c_p_c() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
}

int main() {
  c_p_c();
  int k, m;
  cin >> k >> m;
  int a[m];
  fo(i, m) cin >> a[i];
  int ans = a[m - 1] - a[0];
  Fo(i, 1, m) { ans = min(a[i - 1] + k - a[i], ans); }
  cout << ans << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <climits>
#include <iostream>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
  int K, N, A[2 * 100000 + 1];
  cin >> K >> N;
  rep(i, N) { cin >> A[i]; }
  int maxB = 0;
  rep(i, N - 1) {
    int b = A[i + 1] - A[i];
    if (maxB < b) {
      maxB = b;
    }
  }
  int bEnd = A[0] + (K - A[N - 1]);
  if (maxB < bEnd) {
    maxB = bEnd;
  }
  cout << (K - maxB) << endl;
  return 0;
}


Error: -11

Fixed submission:

#include <climits>
#include <iostream>
#define rep(i, n) for (int i = 0; (i) < (int)(n); i++)
using namespace std;
int main() {
  long long K, N, A[2 * 100000000 + 1];
  cin >> K >> N;
  rep(i, N) { cin >> A[i]; }
  A[N] = K;
  int maxB = 0;
  int sum = 0;
  rep(i, N) {
    int b = A[i + 1] - A[i];
    sum += b;
    if (maxB < b) {
      maxB = b;
    }
  }
  cout << (sum - maxB) << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
#include <vector>
#define ll unsigned long long int
#define vi vector<ll>
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define iiii pair<ii, ii>
#define pb push_back
#define fi first
#define se second
using namespace std;
ll d, n;
ll a[(ll)4e5 + 5];
ll ong[(ll)4e5 + 5];

int main() {
  cin >> d >> n;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll nbaru = n + n - 1;
  ll j = 0;
  for (ll i = 0; i < nbaru; i++) {
    if (i >= n) {
      a[i] = a[j++] + d;
    }
  }
  //	for(ll i = 0;i<nbaru;i++) cout<<a[i]<<" ";cout<<"\\n";
  for (ll i = 1; i < nbaru; i++) {
    ong[i - 1] = a[i] - a[i - 1];
  }
  for (ll i = 1; i < nbaru; i++)
    ong[i] += ong[i - 1];
  //	for(ll i= 0;i<nbaru;i++) cout<<ong[i]<<" ";cout<<"\\n";
  j = 0;
  ll mini = ong[n - 2];
  for (ll i = n - 1; i < nbaru - 1; i++) {
    mini = min(mini, ong[i] - ong[j]);
    //		cout<<ong[i]-ong[j]<<"\\n";
    j++;
  }
  cout << mini << "\\n";
  //	cout<<mini<<"\\n";
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
#include <vector>
#define ll unsigned long long int
#define vi vector<ll>
#define ii pair<ll, ll>
#define iii pair<ii, ll>
#define iiii pair<ii, ii>
#define pb push_back
#define fi first
#define se second
using namespace std;
ll d, n;
ll a[(ll)2e5 + 5];
ll ong[(ll)4e5 + 5];

int main() {
  cin >> d >> n;
  ll ans = 0;
  for (ll i = 0; i < n; i++) {
    cin >> a[i];
  }
  ll nbaru = n + n;
  ll j = 0;
  for (ll i = 0; i < nbaru; i++) {
    if (i >= n) {
      a[i] = a[j++] + d;
    }
  }
  //	for(ll i = 0;i<nbaru;i++) cout<<a[i]<<" ";cout<<"\\n";
  for (ll i = 1; i < nbaru; i++) {
    ong[i - 1] = a[i] - a[i - 1];
  }
  for (ll i = 1; i < nbaru; i++)
    ong[i] += ong[i - 1];
  //	for(ll i= 0;i<nbaru;i++) cout<<ong[i]<<" ";cout<<"\\n";
  j = 0;
  ll mini = ong[n - 2];
  for (ll i = n - 1; i < nbaru; i++) {
    mini = min(mini, ong[i] - ong[j++]);
  }
  cout << mini << "\\n";
  //	cout<<mini<<"\\n";
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i;
  long long sum = 0;
  long long arr[200005];
  scanf("%lld%lld", &n, &k);
  for (i = 0; i < k; i++) {
    scanf("%lld", &arr[i]);
  }
  sort(arr, arr + k);
  for (i = 1; i < k; i++) {
    sum = max(sum, arr[i] - arr[i - 1]);
  }
  sum = max(sum, n - arr[k - 1] + arr[0]);
  printf("%lld", n - sum);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, k, i;
  long long sum = 0;
  long long arr[100005];
  scanf("%lld%lld", &n, &k);
  for (i = 0; i < k; i++) {
    scanf("%lld", &arr[i]);
  }
  sort(arr, arr + k);
  for (i = 1; i < k; i++) {
    sum = max(sum, arr[i] - arr[i - 1]);
  }
  sum = max(sum, n - arr[k - 1] + arr[0]);
  printf("%lld", n - sum);
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n), d(n);
  rep(i, n) cin >> a[i];
  for (int i = 1; i < n; i++) {
    d[i - 1] = a[i] - a[i - 1];
    // cout << d[i] << endl;
  }
  d[n - 1] = k - a[n - 1] + a[0];
  // rep(i, n) cout << d[i];
  cout << k - *max_element(d.begin(), d.end()) << endl;
  return 0;
}

Error: -6
Fatal glibc error: malloc assertion failure in sysmalloc: (old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)


Fixed submission:

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  ll k, n;
  cin >> k >> n;
  vector<ll> a(n), d(n);
  rep(i, n) cin >> a[i];
  for (int i = 1; i <= n; i++) {
    d[i] = a[i] - a[i - 1];
    // cout << d[i] << endl;
  }
  d[n - 1] = min(d[n - 1], k - a[n - 1]);
  cout << accumulate(d.begin(), d.end(), 0) << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a, b, c;
  cin >> K >> N;
  a = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int j = 0; j < N - 1; j++) {
    b = vec.at(j + 1) - vec.at(j);
    if (a < b) {
      a = b;
    }
  }
  c = K + vec.at(0) - vec.at(N - 1);
  if (a < c) {
    a = c;
  }
  cout << K - a << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int K, N, a, b, c; // b:家間の距離
  cin >> K >> N;
  a = 0;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int j = 0; j < N - 1; j++) {
    b = vec.at(j + 1) - vec.at(j);
    if (a < b) {
      a = b;
    }
  }
  c = K + vec.at(0) - vec.at(vec.size());
  if (a < c) {
    a = c;
  }
  cout << K - a << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
const int INF = pow(10, 9) + 7;
int main() {
  int K, N;
  cin >> K >> N;
  int A[2 * N];
  int t = 0;
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    A[t++] = v;
    if (v != 0)
      A[t++] = v - K;
  }
  sort(A, A + t);
  int MIN = INF;
  for (int i = 0; i < N; i++) {
    MIN = min(MIN, A[i + N - 1] - A[i]);
  }
  cout << MIN << endl;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int K, N;
  cin >> K >> N;
  int A[2 * N];
  int t = 0;
  for (int i = 0; i < N; i++) {
    int v;
    cin >> v;
    A[t++] = v;
    if (v != 0)
      A[t++] = v - K;
  }
  int M = K / 2;
  int MAX = 0;
  for (int i = 0; i < M; i++) {
    MAX = max(MAX, A[i + N - 1] - A[i]);
  }
  cout << MAX << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[1000005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 1; i <= k; i++) {
    if (i == 1)
      ans = min(ans, n - (a[1] + n - a[k]));
    else
      ans = min(ans, n - (a[i] - a[i - 1]));
  }
  cout << ans;
  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int a[100005];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= k; i++) {
    cin >> a[i];
  }
  int ans = 1e9;
  for (int i = 1; i <= k; i++) {
    if (i == 1)
      ans = min(ans, n - (a[1] + n - a[k]));
    else
      ans = min(ans, n - (a[i] - a[i - 1]));
  }
  cout << ans;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int a[200002];
int main() {
  int c, n;
  cin >> c >> n;
  int i;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  int ans = 0;
  for (i = 2; i <= n; i++) {
    ans = max(ans, a[i] - a[i - 1]);
  }
  ans = max(ans, c + a[1] - a[n]);
  cout << c - ans << endl;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int a[200002];
int main() {
  int n, p;
  cin >> n >> p;
  int i;
  for (i = 1; i <= n; i++)
    cin >> a[i];
  sort(a + 1, a + 1 + n);
  int ans = -1;
  for (i = 2; i <= n; i++) {
    ans = max(ans, a[i] - a[i - 1]);
  }
  cout << p - ans << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <stdio.h>
int main(void) {
  int k, n, a[10000000], b[10000000], i, p = 0, l;
  scanf("%d%d", &k, &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i != 0) {
      b[i] = a[i] - a[i - 1];
    }
  }
  b[0] = k - a[n - 1] + a[0];
  std::sort(b, b + n);
  for (i = 0; i < n - 1; i++) {
    p += b[i];
  }
  printf("%d\\n", p);
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <stdio.h>
int main(void) {
  int k, n, a[100000000], b[10000000], i, p = 0, l;
  scanf("%d%d", &k, &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    if (i != 0) {
      b[i] = a[i] - a[i - 1];
    }
  }
  b[0] = k - a[n - 1] + a[0];
  std::sort(b, b + n);
  for (i = 0; i < n - 1; i++) {
    p += b[i];
  }
  printf("%d\\n", p);
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;

int main() {
  int K, N, maxv = 0;
  int A[1000000];

  cin >> K >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  maxv = K - A[N - 1] + A[0];
  for (int i = 0; i < N; i++) {
    maxv = max(maxv, A[i + 1] - A[i]);
  }

  cout << K - maxv << endl;
}


Error: 0

Fixed submission:

#include <iostream>
using namespace std;

int main() {
  int K, N, maxv = 0;
  int A[100000];

  cin >> K >> N;

  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }

  maxv = K - A[N - 1] + A[0];
  for (int i = 0; i < N; i++) {
    maxv = max(maxv, A[i + 1] - A[i]);
  }

  cout << K - maxv << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int K, n;
  cin >> K >> n;
  int A[n];
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int ans = (K - A[n - 1]) + A[0];
  for (int i = 1; i < n; i++) {
    ans = max(ans, A[i] - A[i - 1]);
  }

  cout << K - ans;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int main() {
  int K, n;
  int A[n];
  cin >> K >> n;
  for (int i = 0; i < n; i++)
    cin >> A[i];
  int ans = (K - A[n - 1]) + A[0];
  for (int i = 1; i < n; i++) {
    ans = max(ans, A[i] - A[i - 1]);
  }

  cout << K - ans;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  int a[200001];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m, ans;
  ans = a[n - 1] - a[0];
  for (int i = 0; i < n - 1; i++) {
    int s = (k - a[i + 1]) + a[i];
    ans = min(ans, s);
  }
  cout << ans << endl;
  return 0;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int main() {
  int k, n;
  cin >> k >> n;
  int a[100001];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  int m, ans;
  ans = a[n - 1] - a[0];
  for (int i = 0; i < n - 1; i++) {
    int s = (k - a[i + 1]) + a[i];
    ans = min(ans, s);
  }
  cout << ans << endl;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[200005];
void solve() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = a[n - 1] - a[0];
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - a[i] + a[i - 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //	cin>> t;
  while (t--)
    solve();
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
int a[100005];
void solve() {
  int k, n;
  cin >> k >> n;
  int ans = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  ans = a[n - 1] - a[0];
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - a[i] + a[i - 1]);
  }
  cout << ans << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  //	cin>> t;
  while (t--)
    solve();
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int l = 0;
  for (int i = 0; i < N - 1; i++)
    l = max(l, A.at(i + 1) - A.at(i));
  cout << min(K - l, A.at(N - 1) - A.at(0)) << endl;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K, N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A.at(i);
  int l = 0;
  for (int i = 0; i < N - 1; i++)
    l = max(l, A.at(i + 1) - A.at(i));
  cout << min(K - l, A.at(N - 1) - A.at(0)) << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);
  vector<int> B(N);
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  for (int i = 0; i < N - 1; i++) {
    B[i] = A[i + 1] - A[i];
  }
  B[N - 1] = K + A[0] - A[N - 1];
  sort(B.begin(), B.end());
  cout << K - B[N - 1] << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 3) >= this->size() (which is 3)


Fixed submission:

#include <bits/stdc++.h>
using namespace std;

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> A.at(i);
  }

  cout << A.at(N) - A.at(1) << endl;
}