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

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

#define clr(i, j) memset(i, j, sizeof(i))
#define pb push_back
#define PI acos(-1)
#define MOD ((int)1e9 + 7)
typedef long long ll;

//-*-*-*-*-*-*-*-*-

const int N = 2e5 + 100;
ll visited[100005];
// ll a[200000];

#define lop(i, n) for (int i = 0; i < n; ++i)
// ll n,m,mod;

int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

const int MAX = 2e5 + 10;
void finis() { cout << -1; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll ans = 0;
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}


Error: -11

Fixed submission:

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

#define clr(i, j) memset(i, j, sizeof(i))
#define pb push_back
#define PI acos(-1)
#define MOD ((int)1e9 + 7)
typedef long long ll;

//-*-*-*-*-*-*-*-*-

const int N = 2e5 + 100;
ll visited[100005];
// ll a[200000];

#define lop(i, n) for (int i = 0; i < n; ++i)
// ll n,m,mod;

int dx[4] = {1, 0, 0, -1};
int dy[4] = {0, 1, -1, 0};

const int MAX = 2e5 + 10;
void finis() { cout << -1; }

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ll ans = 0;
  ll n, k;
  ll a[n];
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <chrono>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < k; i++)
    ans += p[i];
  cout << ans;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <chrono>
#include <iostream>
#include <list>
#include <map>
#include <set>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main() {
  int n, k;
  vector<int> p;
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < k; i++)
    ans += p[i];
  cout << ans;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int p[1001];
  int i;

  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  sort(p, p + n);

  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += p[i];
  }
  printf("%d\\n", sum);

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int p[100];
  int i;

  for (i = 0; i < n; i++) {
    scanf("%d", &p[i]);
  }

  sort(p, p + n);

  int sum = 0;
  for (i = 0; i < k; i++) {
    sum += p[i];
  }
  printf("%d\\n", sum);

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

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  int N;
  cin >> N;
  int K;
  cin >> K;
  std::vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  rep(i, K) { ans += p[i]; }
  cout << ans << endl;

  return 0;
}


Error: 0

Fixed submission:

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <string>
#include <unordered_map>
#include <vector>

#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips:
// You use the default template now. You can remove this line by using your
// custom template)
int main() {
  long long N;
  scanf("%lld", &N);
  long long K;
  scanf("%lld", &K);
  std::vector<int> p(N);
  for (int i = 0; i < N; i++) {
    scanf("%lld", &p[i]);
  }
  sort(p.begin(), p.end());
  long long ans = 0;
  rep(i, K) { ans += p[i]; }
  cout << ans << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int p[n];
  for (int i = 0; i < n; ++i)
    cin >> p[i];
  sort(p, p + n);
  int s = 0;
  for (int i = 0; i < k; ++i)
    s += p[i];
  cout << s;
  return 0;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, p[n];
  cin >> n >> k;
  for (int i = 0; i < n; ++i)
    cin >> p[i];
  sort(p, p + n);
  int s = 0;
  for (int i = 0; i < k; ++i)
    s += p[i];
  cout << s;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int K;
  int ans = 0;
  cin >> N;
  cin >> K;
  long long P[N];
  for (int i = 0; i < N; i++) {
    cin >> P[i];
  }
  sort(P, P + N);
  for (int i = 0; i < K; i++) {
    ans = ans + P[i];
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  int K;
  int ans = 0;
  int P[N];
  cin >> N;
  cin >> K;
  for (int i = 0; i < N; ++i)
    cin >> P[i];
  sort(P, P + N);
  for (int i = 0; i < K; ++i)
    ans = ans + P[i];
  cout << ans << endl;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

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

  // 100個の入力を受け取る
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int X = 0;
  for (int i = 0; i < K; i++) {
    X += vec.at(i);
  }
  cout << X << endl;
}

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


Fixed submission:

#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

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

  // 100個の入力を受け取る
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  int X = 0;
  for (int i = 0; i <= K + 2; i++) {
    X += vec.at(i);
  }
  cout << X << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], sum = 0;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  // reverse(a,a+n);
  for (int i = 0; i < k; i++) {
    sum = sum + a[i];
  }
  cout << sum << endl;
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a[n], k, sum = 0;
  cin >> n >> k;

  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  // reverse(a,a+n);
  for (int i = 0; i < k; i++) {
    sum = sum + a[i];
  }
  cout << sum << endl;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define fileio                                                                 \\
  freopen("http://in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
#define ff first
#define ss second

#define N 2000001
#define M 998244353
#define INF 1000000000000000
std::vector<ll> v;

int main() {
  SPEED;
  ll t;
  t = 1;

  while (t-- > 0) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    ll i;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    ll sum = 0;
    for (i = 0; i < k; i++) {
      sum += a[i];
    }
    cout << sum;
  }
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
// #define ll long long
using namespace std;
#define SPEED                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0);                                                                  \\
  cout.tie(0)
#define fileio                                                                 \\
  freopen("http://in.in", "r", stdin), freopen("out.out", "w", stdout);
#define ll long long
#define pb push_back
#define pll pair<ll, ll>
#define ff first
#define ss second

#define N 2000001
#define M 998244353
#define INF 1000000000000000
std::vector<ll> v;

int main() {
  SPEED;
  ll t;
  cin >> t;

  while (t-- > 0) {
    ll n, k;
    cin >> n >> k;
    ll a[n];
    ll i;
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    sort(a, a + n);
    ll sum = 0;
    for (i = 0; i < k; i++) {
      sum += a[i];
    }
    cout << sum;
  }
}
Problem p02628 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>

using namespace std;

using ints_t = vector<int>;

void process(ints_t &ints, int k) {
  sort(ints.begin(), ints.end(), ::less<int>());
  int sum = accumulate(ints.begin(), ints.begin() + k, 0);
  cout << sum << "\\n";
}

int main() {
  int n, k;
  cin >> n >> k;
  ints_t ints;
  while (n--) {
    int i;
    cin >> i;
    ints.push_back(i);
  }

  process(ints, k);

  return 0;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>

using namespace std;

using ints_t = vector<int>;
using combi_t = vector<int>;

int get_sum(const ints_t &ints, const combi_t &combi) {
  int sum = 0;
  for (int i = 1; i <= combi.size(); ++i) {
    sum += ints[combi[i - 1] - 1];
  }
  return sum;
}

void gen_combis(const ints_t &ints, int k, combi_t &combi, int &min) {
  if (combi.size() == k) {
    int sum = get_sum(ints, combi);
    if (sum < min) {
      min = sum;
    }
    combi.pop_back();
  } else {
    for (int i = 1; i <= ints.size(); ++i) {
      if (find(combi.begin(), combi.end(), i) == combi.end()) {
        combi.push_back(i);
        gen_combis(ints, k, combi, min);
      }
    }

    if (!combi.empty()) {
      combi.pop_back();
    }
  }
}

void process(const ints_t &ints, int k) {
  combi_t combi;
  int min = INT_MAX;
  gen_combis(ints, k, combi, min);
  cout << min << "\\n";
}

int main() {
  int n, k;
  cin >> n >> k;
  ints_t ints;
  while (n--) {
    int i;
    cin >> i;
    ints.push_back(i);
  }

  process(ints, k);

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

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

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

  vector<int> p(n);
  rep(i, n) { cin >> p[i]; }

  sort(p.begin(), p.end());

  int sum = 0;
  rep(i, k) { sum += p[i]; }

  cout << sum << endl;

  return 0;
}


Error: 0

Fixed submission:

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

const int M = 1001001001;

vector<int> p;
int dp[1000][1000];
int n, k;

int buy(int i, int cnt) {
  if (dp[i][cnt] >= 0) {
    return dp[i][cnt];
  }

  int total = 0;

  if (cnt == k) {
    total = 0;
  } else if (i == n) {
    total = M;
  } else {
    total += min(buy(i + 1, cnt), buy(i + 1, cnt + 1) + p[i]);
  }
  dp[i][cnt] = total;

  return total;
}

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

  rep(i, n) {
    int x;
    cin >> x;
    p.push_back(x);
  }

  memset(dp, -1, sizeof(dp));
  cout << buy(0, 0) << endl;

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

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> wage(N);
  for (int i = 0; i < N; i++) {
    cin >> wage.at(i);
  }
  sort(wage.begin(), wage.end());
  int answer = 0;

  for (int i = 0; i < K; i++) {
    answer = answer + wage.at(i);
  }
  cout << answer << endl;
}

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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> wage;
  for (int i = 0; i < N; i++) {
    cin >> wage.at(i);
  }
  sort(wage.begin(), wage.end());
  int answer = 0;

  for (int i = 0; i < K; i++) {
    answer = answer + wage.at(i);
  }
  cout << answer << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

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

int main() {

  int N;
  int K;
  cin >> N >> K;

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

  sort(vec.begin(), vec.end());

  int sum = 0;
  for (int j = 0; j < N; j++) {
    if (j < K) {
      sum += vec.at(j);
    } else {
      break;
    }
  }

  cout << sum << endl;
}


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


Fixed submission:

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

int main() {

  int N;
  int K;
  cin >> N >> K;

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

  sort(vec.begin(), vec.end());

  int sum = 0;
  for (int j = 0; j < K; j++) {
    sum += vec.at(j);
  }

  cout << sum << endl;
}
Problem p02628 (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 n, k, sum = 0;
  cin >> n >> k;
  vector<int> p(n);
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  rep(i, k) { sum += p.at(i); }
  cout << sum << endl;
}

Error: -6
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 0) >= this->size() (which is 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() {
  int n, k, sum = 0;
  cin >> n >> k;
  vector<int> p;
  rep(i, n) cin >> p.at(i);
  sort(p.begin(), p.end());
  rep(i, k) { sum += p.at(i); }
  cout << sum << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  unsigned int n, k;
  cin >> n >> k;
  int a[n];
  int kq = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < k; i++) {
    kq += a[i];
  }
  cout << kq;
  return 0;
}

Error: WA

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k, a[100];
  cin >> n >> k;
  int kq = 0;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a, a + n);
  for (int i = 0; i < n; i++) {
    if (i < k)
      kq += a[i];
  }

  cout << kq;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>

using namespace std;
int p[10000];

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

  int n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p, p + n);
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>

using namespace std;
int p[100];

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

  int n, k, sum = 0;
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  sort(p, p + n);
  for (int i = 0; i < k; ++i) {
    sum += p[i];
  }
  cout << sum << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
int n, x = 0, m;
set<int> s1, s2, s3;
vector<int> v;
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> x;
    v.push_back(x);
  }
  sort(v.begin(), v.end());
  x = 0;
  for (int i = 0; i < m; i++)
    x += v[i];
  cout << x;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int n, m, e = 100, s = 0, r = 0;
  int a[10];
  cin >> n;

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

    for (int j = 0; j < n - 1; j++) {
      if (a[j] > a[j + 1]) {
        r = a[j + 1];
        a[j + 1] = a[j];
        a[j] = r;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (i == m) {
      s = s + a[i];
    }
  }
  cout << s;

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

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, temp, sum = 0, m;
  cin >> m >> n;
  int k[m];
  for (int i = 1; i <= m; i++) {
    cin >> k[i];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (k[i] < k[j]) {
        temp = k[i];
        k[i] = k[j];
        k[j] = temp;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sum += k[i];
  }
  cout << sum;
}


Error: WA

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, temp, sum = 0;
  int k[100], m;
  cin >> m >> n;
  for (int i = 1; i <= m; i++) {
    cin >> k[i];
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (k[i] < k[j]) {
        temp = k[i];
        k[i] = k[j];
        k[j] = temp;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sum += k[i];
  }
  cout << sum;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
bool com(int a, int b) { return (a < b); }
int main() {
  int n, k, i, ans = 0;
  cin >> n >> k;
  int a[n];
  for (i = 0; i < n; i++)
    cin >> a[i];
  sort(a, a + n, com);
  for (i = 0; i < k; i++)
    ans += a[i];
  cout << ans << endl;
  return 0;
}

Error: -11

Fixed submission:

#include <math.h>
#include <stdio.h>
#include <stdlib.h>
int main() {
  int N, i, K, sum = 0, t, j;
  scanf("%d%d", &N, &K);
  int a[N - 1];
  for (i = 0; i < N; i++) {
    scanf("%d", &a[i]);
  }
  if (N < K) {
    return 0;
  } else if (N >= K) {
    for (i = 0; i < N; i = i + 1) {

      for (j = i + 1; j < N; j++) {
        if (a[i] > a[j]) {
          t = a[i];
          a[i] = a[j];
          a[j] = t;
        }
      }
    }
  }
  for (i = 0; i < K; i++) {
    sum = sum + a[i];
  }
  printf("%d\\n", sum);
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int &i : p)
    cin >> i;
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < K; i++)
    ans += p.at(i);
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p(N);
  for (int &i : p)
    cin >> i;
  sort(p.begin(), p.end());
  int ans = 0;
  for (int i = 0; i < 3; i++)
    ans += p.at(i);
  cout << ans << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define getc getchar_unlocked
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve() {
  int n, k;
  cin >> n >> k;
  int a[n];
  f(i, n) cin >> a[i];
  sort(a, a + n);
  int sum = 0;
  f(i, k) sum += a[i];
  cout << sum << '\\n';
  return;
}

signed main() {
  FAST int T = 1;
  //   cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
#define mod 1000000007
#define FAST ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define f(i, n) for (int i = 0; i < n; i++)
#define fp(i, k, n) for (int i = k; i <= n; i++)
#define fr(i, k, n) for (int i = k; i >= n; i--)
#define pb push_back
#define pii pair<int, int>
#define vi vector<int>
#define vii vector<pii>
#define dbg(x) cout << (#x) << " is " << (x) << '\\n'
#define F first
#define S second
#define sz(x) (int)(x).size()
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(), a.end()
#define getc getchar_unlocked
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;
/*---------------------------------------------------------------------------------------------------*/

void solve() {
  int n, k;
  int a[n];
  cin >> n >> k;
  f(i, n) cin >> a[i];
  sort(a, a + n);
  int sum = 0;
  f(i, k) sum += a[i];
  cout << sum << '\\n';
  return;
}

signed main() {
  FAST int T = 1;
  //   cin >> T;
  while (T--) {
    solve();
  }
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, X = 0;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++) {
    X += p.at(i);
  }
  cout << X << endl;
}

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


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  vector<int> p;
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++) {
    cout << p.at(i) << endl;
  }
}