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

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define SCANF(i)                                                               \\
  int i;                                                                       \\
  scanf("%d", &i)
typedef long long ll;
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;
const int IINF = 100000000;
const int MOD = (int)1e9 + 7;
// 約数列挙
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, -1, 0, 1};

signed main() {
  char t;
  cin >> t;
  for (char c = 'a'; c <= 'z'; c++) {
    if (c == t) {
      cout << 'a' << endl;
      return 0;
    }
  }
  cout << 'A' << endl;
} // https://atcoder.jp/contests/abc171/tasks/abc171_a

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define SCANF(i)                                                               \\
  int i;                                                                       \\
  scanf("%d", &i)
typedef long long ll;
using namespace std;
using P = pair<int, int>;
const long long INF = 1LL << 60;
const int IINF = 100000000;
const int MOD = (int)1e9 + 7;
// 約数列挙
vector<long long> divisor(long long n) {
  vector<long long> ret;
  for (long long i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  // sort(ret.begin(), ret.end()); // 昇順に並べる
  return ret;
}
vector<int> dx = {1, 0, -1, 0};
vector<int> dy = {0, -1, 0, 1};

signed main() {
  char t;
  cin >> t;
  for (char c = 'a'; c <= 'z'; c++) {
    if (c == t) {
      cout << 'a' << endl;
      return 1;
    }
  }
  cout << 'A' << endl;
} // https://atcoder.jp/contests/abc171/tasks/abc171_a
Problem p02627 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

int solve() {
  char c;
  cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A';
  else
    cout << 'a';
  return 0;
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}


Error: WA

Fixed submission:

#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define fast                                                                   \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL);
#define pii pair<int, int>
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {
  int p = 0;
  while (n / 2) {
    n = n / 2;
    p++;
  }
  return p;
}
int poww(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = ((pro % mod) * (x % mod) % mod);
    y = y >> 1;
    x = ((x % mod) * (x % mod) % mod);
  }
  return pro;
}
int poww2(int x, int y) {
  int pro = 1;
  while (y) {
    if (y & 1)
      pro = pro * x;
    y = y >> 1;
    x = x * x;
  }
  return pro;
}
bool isprime(int n) {
  if (n == 1)
    return false;
  for (int i = 2; i <= sqrt(n); i++)
    if (n % i == 0)
      return false;
  return true;
}

/*

*/

int solve() {
  char c;
  cin >> c;
  if (c >= 'A' && c <= 'Z')
    cout << 'A';
  else
    cout << 'a';
}

int32_t main() {
  fast;
  int t = 1;
  // cin>>t;
  while (t--) {
    solve();
  }
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <bits/stdc++.h>
#include <math.h> //pow(x,y)=x^y
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

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

  rep(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end());

  rep(i, K) { sum += A.at(i); }
  cout << sum << endl;
}


Error: WA

Fixed submission:

#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <bits/stdc++.h>
#include <math.h> //pow(x,y)=x^y
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ll long long
using namespace std;

int main() {
  int N, K, sum;
  sum = 0;
  vector<int> A(N);
  cin >> N >> K;
  rep(i, N) { cin >> A.at(i); }
  sort(A.begin(), A.end());

  rep(i, K) { sum += A.at(i); }
  cout << sum << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define in insert
#define MP make_pair
#define F first
#define S second
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void inout() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  ll ara[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  sort(ara + 1, ara + n + 1);
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += ara[i];
  }
  cout << sum;
}
int main() {
  faster();
  // inout();
  solve();
  return 0;
}

Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PB push_back
#define in insert
#define MP make_pair
#define F first
#define S second
void faster() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
void inout() {
  freopen("in.txt", "r", stdin);
  freopen("out.txt", "w", stdout);
}
void solve() {
  ll n, k;
  cin >> n >> k;
  ll ara[n + 10];
  for (int i = 1; i <= n; i++) {
    cin >> ara[i];
  }
  sort(ara + 1, ara + n + 1);
  ll sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += ara[i];
  }
  cout << sum;
}
int main() {
  faster();
  inout();
  solve();
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH
*RANJAN******************************************************
***********************************************************************************************/
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);

    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i, a, b) for (int i = a; i < b; i++)
#define meme(a, b) memset(a, b, sizeof(a)); // works only for 0 and -1
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  int arr[n];
  fr(i, n) cin >> arr[i];
  sort(arr, arr + n);
  ll sum = 0;
  fr(i, k) sum += arr[i];
  cout << sum;
  return 0;
}


Error: -6
*** stack smashing detected ***: terminated


Fixed submission:

/**********************************************************************************************
******************************AUTHOR:**********************************************************
****************************ASHISH
*RANJAN******************************************************
***********************************************************************************************/
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstring>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
using namespace std::chrono;
/*
auto start = high_resolution_clock::now();
auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start);

    cout << "Time taken by function: "
         << duration.count() << " microseconds" << endl;
*/
#define fast()                                                                 \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(NULL)
#define ll long long
#define mod 1000000007
#define fr(i, n) for (int i = 0; i < n; i++)
#define frs(i, a, b) for (int i = a; i < b; i++)
#define meme(a, b) memset(a, b, sizeof(a)); // works only for 0 and -1
int main() {
  fast();
  int n, k;
  cin >> n >> k;
  int arr[k];
  fr(i, n) cin >> arr[i];
  sort(arr, arr + n);
  ll sum = 0;
  fr(i, k) sum += arr[i];
  cout << sum;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int N, K;
  int P;
  int price = 0;

  cin >> N >> K;

  vector<int> A(N);

  for (int i = 0; i < N; i++) {
    cin >> P;
    A.at(i) = P;
  }
  sort(A.begin(), A.end());

  for (int i = 0; i < K; i++) {
    price = price + A.at(i);
  }

  cout << price << 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;
  int P;
  int price = 0;
  vector<int> A;

  cin >> N >> K;

  for (int i = 0; i < N; i++) {
    cin >> P;
    A.at(i) = P;
  }
  sort(A.begin(), A.end());

  for (int i = 0; i < K; i++) {
    price = price + A.at(i);
  }

  cout << price << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include "bits/stdc++.h"
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int64_t i, j, k, l; // preparation for
int main() {
  int n, k, s;
  cin >> n >> k;
  s = 0;
  int p[n];
  int a[1001] = {0};
  for (i = 0; i < n; i++) {
    cin >> p[i];
    a[p[i]] += 1;
  }
  j = 0;
  while (k > 0) {
    if (a[j] != 0) {
      s += j;
      a[j] -= 1;
      k -= 1;
    } else {
      j += 1;
    }
  }
  cout << s;
  return 0;
}

Error: WA

Fixed submission:

#include "bits/stdc++.h"
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;
int64_t i, j, k, l; // preparation for
int main() {
  int n, k, s;
  cin >> n >> k;
  s = 0;
  int p[n];
  int a[101] = {0};
  for (i = 0; i < n; i++) {
    cin >> p[i];
    a[p[i]] += 1;
  }
  i = 0;
  while (k > 0) {
    if (a[i] != 0) {
      s += i;
      a[i] -= 1;
      k -= 1;
    } else {
      i += 1;
    }
  }
  cout << s;
  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> vec(N);
  int money = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < K; i++) {
    money += vec.at(i);
  }
  cout << money << 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);
  int money = 0;
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  for (int i = 0; i < K; i++) {
    money += vec.at(i);
  }
  cout << money << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 998244353;
constexpr int MAX = 510000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll ret = 0;
  for (int i = 0; i < k; i++)
    ret += a[i];
  cout << ret << endl;
}

Error: -11

Fixed submission:

#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits.h>
#include <map>
#include <set>
#include <utility>
#include <vector>
using namespace std;
using P = pair<int, int>;
using ll = long long;
constexpr int MOD = 998244353;
constexpr int MAX = 510000;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++)
    cin >> a[i];
  sort(a.begin(), a.end());
  ll ret = 0;
  for (int i = 0; i < k; i++)
    ret += a[i];
  cout << ret << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, n, k, p[1000], sum = 0;
  scanf("%d %d", &n, &k);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  sort(p, p + n);
  for (i = 0; i < k; i++)
    sum += p[i];
  printf("%d\\n", sum);
  return 0;
}


Error: -11

Fixed submission:

#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
int main(void) {
  int i, n, k, p[1000], sum = 0;
  scanf("%d %d", n, k);
  for (i = 0; i < n; i++)
    scanf("%d", &p[i]);
  sort(p, p + n);
  for (i = 0; i < k; i++)
    sum += p[i];
  printf("%d\\n", sum);
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

/*
        If they say
    Who cares if one more light goes out?
    In a sky of a million stars
    It flickers, flickers
    Who cares when someone's time runs out?
    If a moment is all we are
    We're quicker, quicker
    Who cares if one more light goes out?
    Well I do
*/

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

#define gcd(a, b) __gcd(a, b)
#define lcm(a, b) ((a) / gcd(a, b)) * (b)
#define all(x) x.begin(), x.end()

#define ll long long
#define ull unsigned long long
#define VI vector<int>
#define VLL vector<ll>
#define VS vector<string>
#define MPII map<int, int>
#define SET set<int>
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define fast_io                                                                \\
  ios_base::sync_with_stdio(false);                                            \\
  cin.tie(0), cout.tie(0);

ll MOD = 1e9 + 7;

ll add(ll a, ll b) {
  a += b;
  a %= MOD;
  if (a < 0)
    a += MOD;
  return a;
}
// doesn't work for neg numbers

ll mult(ll a, ll b) {
  if (a > MOD)
    a %= MOD;
  if (b > MOD)
    b %= MOD;
  ll ans = (a * b) % MOD;
  if (ans < 0)
    ans += MOD;
  return ans;
}
// doesn't work for neg numbers

ll pw(ull a, ull b) {
  ll r = 1;
  while (b) {
    if (b & 1)
      r = mult(r, a);
    a = mult(a, a);
    b >>= 1;
  }
  return r;
}
// doesn't work for neg numbers

void solve() {
  int a, b;
  cin >> a >> b;
  int arr[a];
  for (int i = 0; i < a; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + a);
  int ans = 0;
  for (int i = 0; i < b; i++)
    ans += arr[i];
  cout << ans << endl;
}

int main() {
  /*	#if ONLINE_JUDGE
            freopen("inputf.in", "r", stdin);
            freopen("outputf.in", "w", stdout);
          #endif
  */
  fast_io;
  ll t, k = 0;
  t = 1;
  while (t--) {
    // k++;
    // cout<<"Case "<<k<<": ";
    solve();
  }
}


Error: -11

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b;
  cin >> a >> b;
  vector<int> v;
  for (int i = 0; i < a; i++)
    cin >> v[i];
  sort(v.begin(), v.end());
  int ans = 0;
  for (int i = 0; i < b; i++)
    ans += v[i];
  cout << ans << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Time Limit Exceeded

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

using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::string;
using std::vector;

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

Error: TLE

Fixed submission:

#include <cmath>
#include <iostream>
#include <string>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::pow;
using std::string;
using std::vector;

int main() {
  int K, N, c, sum, result = 1000000, count;
  cin >> N >> K;
  vector<int> p(N);
  for (int i = 0; i < N; i++)
    cin >> p.at(i);
  for (int i = 0; i < pow(2, N); i++) {
    c = i;
    sum = 0;
    count = 0;
    for (int j = 0; j < N; j++) {
      if (c % 2 == 1) {
        sum += p.at(j);
        count++;
      }
      c = int(c / 2);
    }
    if (result > sum && count >= K)
      result = sum;
  }
  cout << result;
}
Problem p02628 (C++) — buggy submission, verdict: Time Limit Exceeded

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

#define DEBUG_ENABLED 1

typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  vector<ll> p;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    p.push_back(a);
  }

  ll min = 0;
  sort(p.begin(), p.end());
  for (int i = 0; i < K; i++) {
    min += p.at(i);
  }

  cout << min << endl;
  return 0;
}


Error: TLE

Fixed submission:

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

#define DEBUG_ENABLED 1

typedef long long ll;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll N, K;
  cin >> N >> K;

  vector<ll> p;
  for (int i = 0; i < N; i++) {
    ll a;
    cin >> a;
    p.push_back(a);
  }

  ll min = 1000 * 1000;

  vector<int> order;
  for (int i = 0; i < N; i++) {
    order.push_back(i);
  }

  do {
    ll sum = 0;
    for (int i = 0; i < K; i++) {
      sum += p.at(order.at(i));
    }

    if (sum < min) {
      min = sum;
    }

  } while (next_permutation(order.begin(), order.end()));

  cout << min << endl;
  return 0;
}
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;
typedef long long ll;
typedef pair<int, int> P;

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

Error: 0

Fixed submission:

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

int main() {
  int n, k;
  int p[n];
  cin >> n >> k;
  rep(i, n) cin >> p[i];
  sort(p, p + n);
  int 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>
#include <iostream>
int main() {
  int n, k, sum, vec[1000];
  sum = 0;
  std::cin >> n >> k;
  for (int i = 0; i < n; i++) {
    std::cin >> vec[i];
  }
  std::sort(vec, vec + n);
  for (int i = 0; i < k; i++) {
    sum = sum + vec[i];
  }
  std::cout << sum;
}


Error: WA

Fixed submission:

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

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

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

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>
using namespace std;
int main() {
  int n, k;
  int p[n];
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> p[i];
  sort(p, p + n);
  int sum = 0;
  for (int i = 0; i < k; i++)
    sum += p[i];
  cout << sum << endl;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <deque>
#include <iostream>
#include <set>
#include <vector>
using namespace std;
int main() {
  int k, n;
  cin >> k;
  cin >> n;
  int arr[k + 1];

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

  sort(arr, arr + k);

  int sum = 0;

  for (int j = 0; j < n; ++j) {
    sum += arr[j];
  }
  cout << sum << endl;
}

Error: 0

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int K, N;
  cin >> N >> K;
  int p[100];
  for (int i = 0; i < N; i++) {
    cin >> p[i];
  }
  int minm = p[0], index = 0, sum = 0;
  for (int i = 0; i < K; i++) {
    for (int j = 0; j < N; j++) {
      if (minm > p[j] && p[j] != '\\0') {
        minm = p[j];
        index = j;
      }
    }
    sum += minm;
    p[index] = '\\0';
    for (int j = 0; j < N; j++) {
      if (p[j] != '\\0') {
        minm = p[j];
        break;
      }
    }
  }
  cout << sum << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

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

int main() {
  int n, k, res(0);
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++)
    cin >> vec[i];
  sort(vec.begin(), vec.end());
  for (int i = 0; i < k; i++)
    res += vec[i];
  cout << res << endl;
  ios::sync_with_stdio(false);
  cin.tie();
  cout.tie();
  return 0;
}

Error: WA

Fixed submission:

#include <iostream>

using namespace std;
int main() {
  int n, m, 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;
}