alexjercan/bugnet huggingface dataset:
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll mod = 1000000007;
const int INF = 1 << 29;

int main() {
  ll K, N;
  cin >> K >> N;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];

  ll res = INF;
  // 時計回り
  res = min(res, a[N - 1] - a[0]);
  for (int i = 1; i < N; ++i) {
    ll dist = (a[N - 1] - a[i]) + (K - a[N - 1]) + a[i - 1];
    res = min(res, dist);
  }
  // 反時計回り
  res = min(res, a[N - 1] - a[0]);
  for (int i = N - 2; i >= 0; --i) {
    ll dist = a[i] + (K - a[i + 1]);
    res = min(res, dist);
  }
  cout << res << endl;
}


Error: TLE

Fixed submission:

#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
using P = pair<ll, ll>;

template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll mod = 1000000007;
const int INF = 1 << 29;

struct edge {
  int to;
  int cost;
};
#define MAX_V 1000000
ll d[MAX_V];
vector<edge> G[MAX_V];
void dijkstra(int V, int s) { // グラフ,距離,ノードの数,スタート
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first)
      continue;

    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}

int main() {
  int K, N;
  cin >> K >> N;
  vector<int> a(N);
  rep(i, N) cin >> a[i];

  ll res = INF;
  // 時計回り
  edge e = {0, (K - a[N - 1]) + (a[0] - 0)};
  G[N - 1].push_back(e);
  for (int i = 0; i < N; ++i) {
    e = {i + 1, a[i + 1] - a[i]};
    G[i].push_back(e);
  }
  for (int i = 0; i < N; ++i) {
    dijkstra(N, i);
    sort(d, d + N);
    res = min(res, d[N - 1]);
  }
  for (int i = 0; i < N; ++i) {
    G[i].clear();
  }
  // 反時計回り
  e = {N - 1, (K - a[N - 1]) + (a[0] - 0)};
  G[0].push_back(e);
  for (int i = N - 1; i > 0; --i) {
    e = {i - 1, a[i] - a[i - 1]};
    G[i].push_back(e);
  }
  for (int i = 0; i < N; ++i) {
    dijkstra(N, i);
    sort(d, d + N);
    res = min(res, d[N - 1]);
  }
  cout << res << 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> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  vector<int> vec1(N - 1);
  for (int i = 0; i < N - 1; i++) {
    vec1.at(i) = vec.at(i + 1) - vec.at(i);
  }
  vec1.push_back(K - vec.at(N - 1) + vec.at(0));
  for (int x : vec1) {
    cerr << "debug " << x << endl;
  }

  // O(NlogN)
  sort(vec1.begin(), vec1.end());
  cout << K - vec1.at(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> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }

  vector<int> vec1(N - 1);
  for (int i = 0; i < N; i++) {
    vec1.at(i) = vec.at(i + 1) - vec.at(i);
  }
  vec1.push_back(K - vec.at(N - 1) + vec.at(0));

  sort(vec1.begin(), vec1.end());
  cout << K - vec1.at(N - 1) << endl;
  sort(vec1.begin(), vec1.end());
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main() {
  int k, n;
  cin >> k >> n;

  vector<int> arr(n);
  for (int &e : arr)
    cin >> e;

  sort(begin(arr), end(arr));

  int minima = 1e9;
  for (int i = 0; i < n; i++) {
    int other = (i + n - 1) % n;
    int d = (arr[other] - arr[i]);
    if (d < 0)
      d += k;

    minima = min(minima, d);
  }

  cout << minima << endl;

  return 0;
}

Error: WA

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int i, j, k, arr[100005], n, large, small, a, b;
  cin >> k;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  large = arr[1];
  for (i = 1; i <= n; i++) {
    if (arr[i] > large) {
      large = arr[i];
    }
  }
  small = 99999999;
  for (i = 1; i <= n; i++) {
    if (arr[i] == 0) {

    } else {
      if (arr[i] < small) {
        small = arr[i];
      }
    }
  }

  a = large - small;
  b = (k + small) - large;
  if (a >= b) {
    cout << b;
  } else {
    cout << a;
  }

  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long k, n, temp, t;
  cin >> k >> n;
  long long a[n], m[n - 1];
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }

  t = (a[0] + (k - a[n - 1]));

  for (long long j = 0; j < n - 1; j++) {
    m[j] = abs(k - (abs(a[j] - a[j + 1])));
  }
  long long max = m[0];
  for (long long i = 0; i < n - 1; i++) {
    if (m[i] < max)
      max = m[i];
  }

  if ((k - t) <= max)
    cout << k - t << "\\n";
  else if ((k - t) >= max)
    cout << max << "\\n";
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long k, n, temp, t;
  cin >> k >> n;
  long long a[n], m[n - 1];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

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

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

  if (t < max)
    cout << t << "\\n";
  if (t > max)
    cout << max << "\\n";
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 2e5 + 10;

int n, k;

int a[MAXN];

const int MOD = 1e9 + 7;

int main() {
  cin >> k >> n;

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

  maxVal = max(maxVal, k - a[n - 1] + a[0]);

  cout << k - maxVal;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5 + 10;

int n, k;

int a[MAXN];

const int MOD = 1e9 + 7;

int main() {
  cin >> k >> n;

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

  maxVal = max(maxVal, k - a[n - 1] + a[0]);

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

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;

void solve() {
  ll k, n, x;

  cin >> k >> n;
  ll a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  x = a[0];
  for (int i = 0; i + 1 < n; i++) {
    a[i] = a[i + 1] - a[i];
  }
  a[n - 1] = k - a[n - 1] + x;
  ll ans = k - *max_element(a, a + n);
  cout << ans;
}
int main() {
  /* #ifndef ONLINE_JUDGE
     freopen("ques.txt","r",stdin);
     freopen("ans.txt","w",stdout);
   #endif
    int t;
    cin>>t;
    while(t--) */
  {
    solve();
    cout << "\\n";
  }
  return 0;
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef long long ll;
using namespace std;
const ll mod = 1e9 + 7;

void solve() {
  ll k, n, x;
  ll a[n];
  cin >> k >> n;
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  x = a[0];
  sort(a, a + n);
  for (int i = 0; i + 1 < n; i++) {
    a[i] = a[i + 1] - a[i];
  }
  a[n - 1] = k - a[n - 1] + x;

  ll ans = k - *max_element(a, a + n);
  cout << ans;
}
int main() {
  /*#ifndef ONLINE_JUDGE
    freopen("ques.txt","r",stdin);
    freopen("ans.txt","w",stdout);
  #endif
   int t;
   cin>>t;
   while(t--) */
  {
    solve();
    cout << "\\n";
  }
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 100010;

ll dis(ll x, ll y, ll n) { return n - min(abs(x - y), n - abs(x - y)); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, m;
  cin >> n >> m;
  ll ar[m];
  for (ll i = 0; i < m; ++i) {
    cin >> ar[i];
  }
  ll ans = INT_MAX;
  for (ll i = 0; i < m; ++i) {
    ans = min(ans, dis(ar[i], ar[(i + 1) % m], n));
    ans = min(ans, dis(ar[i], ar[(i - 1 + m) % m], n));
  }
  cout << ans;

  return (0);
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)
#define pi pair<ll, ll>
using namespace std;
const ll N = 100010;

ll dis(ll x, ll y, ll n) { return n - min(abs(x - y), n - abs(x - y)); }

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);

  ll n, m;
  cin >> n >> m;
  ll ar[m];
  for (ll i = 0; i < m; ++i) {
    cin >> ar[i];
  }
  ll ans = INT_MAX;
  for (ll i = 0; i < n; ++i) {
    ans = min(ans, dis(ar[i], ar[(i + 1) % m], n));
    ans = min(ans, dis(ar[i], ar[(i - 1 + m) % m], n));
  }
  cout << ans;

  return (0);
}
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[2000005];
int arr2[1000005];
// ll Pow(ll base , ll power)
// void sieve_eratosthenes(int n);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, k, temp, finale = 1e9, sum = 0, mas = -1;
  cin >> k >> n;
  ll x;
  cin >> temp;
  ll first = temp;
  for (ll i = 1; i < n; i++) {
    cin >> x;
    ll dif = x - temp;
    sum += dif;
    mas = max(dif, mas);
    temp = x;
    if (i == n - 1) {
      dif = first - temp + k;
      sum += dif;
      mas = max(dif, mas);
    }
  }
  cout << sum - mas << endl;
}

/*
void sieve_eratosthenes(int n)
    {
bool primes[n+2]={false};
for(int i=3;i<=n;i+=2)
    primes[i]=1;
    primes[2]=1;
for(int i=3;i*i<=n;i+=2)
{
    if(primes[i]==1){
    for(int j=i*i;j<=n;j+=i)
        primes[j]=0;
    }
}
for(int i=2;i<=n;i++)
    if(primes[i]==1)
    cout<<i<<endl;
return;
    }
ll Pow(ll base , ll power)
        {
            if(power==0)return 1;
            ll x = Pow(base,power/2);
            x*=x;
            if(power&1)
                return base*x;
            else
                return x;
        }
*/


Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll arr[200005];
int arr2[1000005];
// ll Pow(ll base , ll power)
// void sieve_eratosthenes(int n);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n, k, temp, finale = 1e9;
  cin >> k >> n;
  for (ll i = 0; i < n; i++) {
    cin >> arr[i];
  }
  ll ans;
  for (ll i = 0; i < n; i++) {
    ans = 0, temp = i + 1;
    for (ll j = i + 1; temp < i + n; j++, temp++) {
      ll var = (j - 1) % n;
      ll var2 = (j % n);
      if (var == 0)
        var = n;
      if (var2 == 0)
        var2 = n;
      ll x = -arr[var] + arr[var2];
      if (x < 0)
        x += k;
      ans += x;
      // cout<<ans<<endl;
    }
    // cout<<ans<<endl;
    finale = min(finale, ans);
  }
  cout << finale << endl;
}

/*
void sieve_eratosthenes(int n)
    {
bool primes[n+2]={false};
for(int i=3;i<=n;i+=2)
    primes[i]=1;
    primes[2]=1;
for(int i=3;i*i<=n;i+=2)
{
    if(primes[i]==1){
    for(int j=i*i;j<=n;j+=i)
        primes[j]=0;
    }
}
for(int i=2;i<=n;i++)
    if(primes[i]==1)
    cout<<i<<endl;
return;
    }
ll Pow(ll base , ll power)
        {
            if(power==0)return 1;
            ll x = Pow(base,power/2);
            x*=x;
            if(power&1)
                return base*x;
            else
                return x;
        }
*/
Problem p02725 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;
int k, n, a[200010], minn;
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int ans = 0;
    int f = (i + n - 1) % n;
    ans = (a[f] - a[i] + k) % k;
    if (i == 0)
      minn = ans;
    else
      minn = min(minn, ans);
  }
  cout << minn;
  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int k, n, a[200010], minn;
int main() {
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    int ans = 0;
    int j = i;
    int f = (i == 0) ? (n - 1) : (i - 1);
    while (1) {
      ans = ans + (a[j + 1] - a[j] + k) % k;
      j++;
      j %= n;
      if (j == f)
        break;
    }
    if (i == 0)
      minn = ans;
    else
      minn = min(minn, ans);
  }
  cout << minn;
  return 0;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int t = 1e6, a[200005];
int main() {
  int i, k, n, p;
  scanf("%d %d", &k, &n);
  scanf("%d", &a[0]);
  for (i = 1; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for (i = 1; i < n; i++) {
    p = k - a[i] + a[i - 1];
    if (p < t)
      t = p;
  }
  p = a[n - 1] - a[0];
  if (p < t)
    t = p;
  printf("%d", t);
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int t = 1e6, a[20005];
int main() {
  int i, k, n, p;
  scanf("%d %d", &k, &n);
  scanf("%d", &a[0]);
  for (i = 1; i < n; i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  for (i = 1; i < n; i++) {
    p = k - a[i] + a[i - 1];
    if (p < t)
      t = p;
  }
  p = a[n - 1] - a[0];
  if (p < t)
    t = p;
  printf("%d", t);
}
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() {
  int k, n, kmax, sa, i, j;

  kmax = 0;
  sa = 0;
  cin >> k >> n;
  int a[n + 1];
  rep(i, n) cin >> a[i];
  kmax = k - a[n - 1] + a[0];
  rep(j, n - 1) {
    // cout << a[j] << endl;
    // cout << a[j+1] << endl;
    // cout << a[2] << endl;
    sa = a[j + 1] - a[j];

    kmax = max(sa, kmax);
  }
  cout << k - kmax << endl;

  return 0;
}

Error: WA

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() {
  int k, n, kmax, sa;
  int a[n];
  cin >> k >> n;
  rep(i, n) cin >> a[i];
  kmax = k - a[n - 1];
  rep(i, n - 1) {
    sa = a[i + 1] - a[i];
    kmax = max(sa, kmax);
  }
  cout << k - kmax << endl;

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

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main() {
  int k, n;
  int sum = 0;
  cin >> k >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> d(n);
  for (int i = 1; i < n; i++) {
    d[i] = a[i] - a[i - 1];
  }
  d[0] = k + a[0] - a[n - 1];
  sort(d.begin(), d.end());
  rep(i, n - 1) sum += d[i];
  cout << sum << endl;
}

Error: -6
terminate called after throwing an instance of 'std::length_error'
  what():  cannot create std::vector larger than max_size()


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
typedef long long ll;
#define _GLIBCXX_DEBUG
int main() {
  int k, n;
  int sum = 0;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  vector<int> d(n);
  for (int i = 1; i < n; i++) {
    d[i] = a[i] - a[i - 1];
  }
  d[0] = k + a[0] - a[n - 1];
  sort(d.begin(), d.end());
  rep(i, n - 1) sum += d[i];
  cout << sum << endl;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int k, n;
  cin >> k >> n;
  int a[200005];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int mxd = 0;
  for (int i = 0; i < n - 1; i++) {
    mxd = max(mxd, a[i + 1] - a[i]);
  }
  mxd = max(mxd, a[0] + k - a[n - 1]);
  cout << k - mxd << endl;
}

Error: WA

Fixed submission:

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

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  int a[200005];
  int c[200005];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (a[i] > k / 2) {
      c[i] = a[i] - k;
    } else {
      c[i] = a[i];
    }
  }
  sort(a, a + n);
  sort(c, c + n);
  int f = c[n - 1] - c[0];
  int g = a[n - 1] - a[0];
  if (f > g) {
    cout << g;
  } else {
    cout << f;
  }
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error


#include <stdio.h>

#define MAX_H 200001
int House[MAX_H];

// always x < y ex) 1 , 19   D:20 (1+20)-19
int GetDistance(int x, int y, int D) {
  int dist = y - x;

  if (dist < 0)
    dist += D;

  return dist;
}

int main() {
#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int K, N;
  scanf("%d %d", &K, &N);

  for (int n = 0; n < N; n++)
    scanf("%d", &House[n]);

#ifdef _WIN32
  printf("input : %d %d\\n", K, N);
  for (int n = 0; n < N; n++)
    printf("%d ", House[n]);
  printf("\\n");
#endif

  int Result = 0;
  for (int i = 0; i < N; i++) {
    int temp = GetDistance(House[i], House[(i + 1) % N], K);
    if (Result < temp)
      Result = temp;
  }

  printf("%d", K - Result);

  return 0;
}


Error: WA

Fixed submission:

#include <stdio.h>

#define MAX_H 20001
int House[MAX_H];

// always x < y ex) 1 , 19   D:20 (1+20)-19
int GetDistance(int x, int y, int D) {
  int dist1 = y - x;
  x += D;
  int dist2 = x - y;

  if (dist1 < dist2)
    return dist1;

  return dist2;
}

int main() {
#ifdef _WIN32
  freopen("input.txt", "r", stdin);
#endif

  int K, N;
  scanf("%d %d", &K, &N);

  for (int n = 0; n < N; n++)
    scanf("%d", &House[n]);

  for (int i = 0; i < N; i++)
    for (int j = i; j < N; j++) {
      int Temp = House[i];
      House[i] = House[j];
      House[j] = Temp;
    }

#ifdef _WIN32
  printf("input : %d %d\\n", K, N);
  for (int n = 0; n < N; n++)
    printf("%d ", House[n]);
  printf("\\n");
#endif

  int Result = 0;
  for (int i = 0; i < N; i++) {
    int temp = GetDistance(House[i], House[(i + 1) % N], K);
    if (Result < temp)
      Result = temp;
  }

  printf("%d", K - Result);

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

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
int main() {
  ARB int k, n;
  cin >> k >> n;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  sort(arr, arr + n);
  int ans = k, sum = 0;
  for (int i = 1; i < n; i++) {
    ans = min(ans, k - arr[i] + arr[i - 1]);
    sum += arr[i] - arr[i - 1];
  }
  ans = min(ans, sum);
  cout << ans;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ARB                                                                    \\
  ios::sync_with_stdio(0);                                                     \\
  cin.tie(0);                                                                  \\
  cout.tie(0);
#define ll long long
#define pp __builtin_popcount
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;
const int maxn = 1e5 + 5;
int main() {
  ARB ll k, n, arr[maxn];
  cin >> k >> n;
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  ll ans = 0;
  for (int i = 0; i < n / 2; i++) {
    if (arr[i] == 0)
      continue;
    else
      ans += (arr[i + 1] - arr[i]);
  }
  for (int i = n; i > n / 2; i--) {
    if (arr[i] == 0)
      continue;
    else
      ans += (arr[i] - arr[i - 1]);
  }
  cout << ans;
}
Problem p02725 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int K, N, i, ans = 0;
  int a[200000];
  int tmp1, tmp2, a0, an;

  cin >> K >> N;

  for (auto i = 0; i < N; i++) {
    cin >> a[i];
  }
  a0 = a[0];
  an = a[N - 1];

  for (i = 0; i < N - 1; i++) {
    tmp1 = a[i];
    tmp2 = a[i + 1];
    a[i] = a[i + 1] - a[i];
  }

  a[N - 1] = K - an + a0;

  sort(a, a + N);

  for (i = 0; i < N - 1; i++) {
    ans = ans + a[i];
  }

  cout << ans;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <vector>
using namespace std;

int main() {
  int K, N, i, ans = 0;
  int a[20000];

  cin >> K >> N;

  for (auto i = 0; i < N; i++) {
    cin >> a[i];
  }
  int b[20000] = {};

  for (i = 0; i < N - 1; i++) {

    b[i] = a[i + 1] - a[i];
  }

  b[N - 1] = K - a[N - 1] + a[0];

  sort(b, b + N);

  for (i = 0; i < N - 1; i++) {
    ans = ans + b[i];
  }

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

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define in_arr(name, size)                                                     \\
  for (int i = 0; i < size; i++)                                               \\
    cin >> name[i];
#define QUICK                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cout << fixed;
#define MOD 1e9 + 7

int main() {
  QUICK

  int maks = 0;
  int a, b;
  cin >> a >> b;
  vector<int> num(b);
  for (int i = 0; i < b; i++)
    cin >> num[i];
  sort(num.begin(), num.end());

  for (int i = 0; i < b - 1; i++) {
    maks = max(maks, num[i + 1] - num[i]);
  }

  maks = max(maks, a - num[b - 1] + num[0]);
  cout << a - maks;

  return 0;
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ll;
typedef long long ull;
typedef long double ld;
#define in_arr(name, size)                                                     \\
  for (int i = 0; i < size; i++)                                               \\
    cin >> name[i];
#define QUICK                                                                  \\
  ios_base::sync_with_stdio(0);                                                \\
  cout << fixed;
#define MOD 1e9 + 7

int main() {
  QUICK

  int a, b;
  cin >> a >> b;
  vector<int> num(b);
  for (int i = 0; i < b; i++) {
    cin >> num[i];
  }
  sort(num.begin(), num.end());
  cout << min(a - (num[b - 1] - num[0]), num[a - 1] - num[0]);

  return 0;
}