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

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

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

Error: -11

Fixed submission:

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

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

int main() {
  int n;
  int k;

  cin >> n >> k;

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

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

  int goukei = 0;
  for (int j = 0; j < k; j++) {
    goukei += fruit.at(j);
    if (j == k - 1) {
      cout << goukei << endl;
    }
  }
}


Error: TLE

Fixed submission:

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

int main() {
  int n;
  int k;

  cin >> n >> k;

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

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

  int goukei = 0;
  for (int j = 0; j < n; j++) {
    goukei += fruit.at(j);
    if (j == n - 1) {
      cout << goukei << endl;
    }
  }
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int n, k, price[1001], total = 0;

  cin >> n >> k;

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

  sort(price, price + n);

  for (int i = 0; i < k; i++)
    total = total + price[i];

  cout << total;
}

Error: WA

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int n, k, price[n + 1], total = 0;

  cin >> n >> k;

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

  sort(price, price + n);

  for (int i = 0; i < k; i++)
    total = total + price[i];

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

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

int main() {
  int n;
  int k;
  cin >> n >> k;
  int p[n];
  int m = 100000;
  for (int i = 0; i < n; i++) {
    cin >> p[i];
  }
  int ans = 0;
  int check = 0;
  for (int i = 0; i <= 1000; i++) {
    for (int j = 0; j < n; j++) {
      if (i == p[j]) {
        ans = ans + p[j];
        check++;
      }
      if (check == k) {
        cout << ans << endl;
        return 0;
      }
    }
  }
}


Error: -11

Fixed submission:

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

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

#include <bits/stdc++.h>
#define ll long long
#define endl "\\n"
#define pb push_back
#define READ(FILE) freopen(FILE, "r", stdin)
#define WRITE(FILE) freopen(FILE, "w", stdout)
#define loop(i, s, e) for (int i = s; i < e; i++)
#define mego fast();
using namespace std;
void fast() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}

ll lcm(ll x, ll y) { return (x * y) / __gcd(x, y); }
int sum(string s) {
  int x = 0, sz = s.size();
  loop(i, 0, sz) x += (s[i] - '0');
  return x;
}
/*
struct node
{
int data;
node *link;
};
typedef node* nodeptr;
void head_insert(nodeptr& head,int x)
{
    nodeptr tmp;
    tmp=new node;
    tmp->data=x;
    tmp->link=head;
    head=tmp;
}
nodeptr search(nodeptr head,int x)
{
    nodeptr cur=head;
    if(cur ==  nullptr)return cur;
    while(cur->data!=x&&cur->link!=nullptr)
    {
        cur=cur->link;
    }
    if(cur->data==x)return cur;
    else return nullptr;
}
void show(nodeptr head)
{
    nodeptr cur=head;
    if(cur==nullptr)return;
   // cout<<head->data<<" ";
    while(cur->link!=nullptr){
        cout<<cur->data<<" ";
        cur=cur->link;
    }
    cout<<endl;
}
*/

int main() {
  mego int n, k, x;
  vector<int> v;
  cin >> n >> k;
  loop(i, 0, n) {
    cin >> x;
    v.pb(x);
  }
  sort(v.begin(), v.end());
  int ans = 0;
  loop(i, 0, k) ans += v[i];
  cout << ans;
  return 0;
}


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 <bits/stdc++.h>
using namespace std;

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

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>
#include <iostream>

using namespace std;

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //	int t;
  //	cin >> t;
  //	while (t--)
  test_case();
  return 0;
}

Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  //	int t;
  //	cin >> t;
  //	while (t--)
  test_case();
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <stdio.h>

int main(void) {
  int n, k;

  scanf("%d", &n);
  scanf("%d", &k);

  int p[n];

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

  int min, tmp;

  for (int i = 0; i < n - 1; i++) {
    min = p[i];
    tmp = i;
    for (int j = i + 1; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        tmp = j;
      }
    }
    p[tmp] = p[i];
    p[i] = min;
  }

  int sum = 0;

  for (int i = 0; i < k; i++) {
    sum += p[i];
  }

  printf("%d", sum);

  return 0;
}

Error: WA

Fixed submission:

#include <stdio.h>

int main(void) {
  int n, k;

  scanf("%d", &n);
  scanf("%d", &k);

  int p[n];

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

  int min, tmp;

  for (int i = 0; i < n - 1; i++) {
    min = p[i];
    for (int j = i + 1; j < n; j++) {
      if (min > p[j]) {
        min = p[j];
        tmp = j;
      }
    }
    p[tmp] = p[i];
    p[i] = min;
  }

  int sum = 0;

  for (int i = 0; i < k; i++) {
    sum += p[i];
  }

  printf("%d", sum);

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

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

  int sum = 0;
  for (int i = 0; i < k; ++i)
    sum += p[i];
  cout << sum << endl;
}

Error: TLE

Fixed submission:

#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
using Graph = vector<vector<int>>;
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

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

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

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

using namespace std;

int main() {
  long long n, k;
  cin >> n >> k;
  vector<int> vec(n, 10000000);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  long long ans = 0;
  for (int i = 0; i < k; i++) {
    ans += vec.at(i);
  }
  cout << ans << endl;
}

Error: 0

Fixed submission:

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

using namespace std;

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  cout << vec.at(0) + vec.at(1) + vec.at(2) << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int N, K, Only1;
  cin >> N >> K;
  if (N == 1) {
    cin >> Only1;
    cout << Only1 << endl;
  } else {

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

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

    int goukei = 0;
    for (int i = 0; i < K; i++) {
      goukei = goukei + nedan.at(i);
    }

    cout << goukei << endl;
  }
}


Error: 0

Fixed submission:

#include <bits/stdc++.h>
#include <iostream>

using namespace std;

int main() {
  int N, K, Only1;
  cin >> N >> K;
  if (N == 1) {
    cin >> Only1;
    cout << Only1 << endl;
  } else {

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

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

    int goukei;
    goukei = nedan.at(0) + nedan.at(1) + nedan.at(2);
    cout << goukei << endl;
  }
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

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

Error: WA

Fixed submission:

#include <iostream>
using namespace std;

void merge(int arr[], int l, int m, int h) {
  int i, j, k;
  int n1 = m - l + 1;
  int n2 = h - m;

  int L[n1], H[n2];

  for (i = 0; i < n1; i++)
    L[i] = arr[l + i];
  for (j = 0; j < n2; j++)
    H[j] = arr[m + 1 + j];

  i = 0;
  j = 0;
  k = l;
  while (i < n1 && j < n2) {
    if (L[i] <= H[j]) {
      arr[k] = L[i];
      i++;
    } else {
      arr[k] = H[j];
      j++;
    }
    k++;
  }

  while (i < n1) {
    arr[k] = L[i];
    i++;
    k++;
  }

  while (j < n2) {
    arr[k] = H[j];
    j++;
    k++;
  }
}

void mergeSort(int arr[], int l, int h) {
  if (l < h) {
    int m = l + (h - l) / 2;

    mergeSort(arr, l, m);
    mergeSort(arr, m + 1, h);

    merge(arr, l, m, h);
  }
}

int main() {
  int n, k, x[n], sum(0);
  cin >> n >> k;
  for (int i = 0; i < n; i++)
    cin >> x[i];
  mergeSort(x, 0, n - 1);
  for (int i = 0; i < k; i++)
    sum += x[i];
  cout << sum;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <bits/stdc++.h>
using namespace std;
bool result(int x, int y, int z, int e) {
  return ((x * x + z * z + y * y + x * y + y * z + z * x) <= e);
}
int main() {
  int n, k;
  cin >> n >> k;
  long *arr = new long[n];
  for (int x = 0; x < n; x++)
    cin >> arr[x];

  sort(arr, arr + n);
  for (int x = 1; x < k; x++)
    arr[0] += arr[x];

  cout << arr[0] << endl;

  return 0;
}


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 = 1; 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 = 1; i <= n; i++) {
    if (i == m) {
      s = s + a[i];
    }
  }
  cout << s;

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

#include <bits/stdc++.h>
using namespace std;
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
#define pb push_back
#define MP make_pair
#define mod 1000000007
#define int long long
signed main() {
  boost;
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int ans = 0;
  sort(arr, arr + n);
  for (int i = 0; i < k; i++)
    ans += arr[i];

  cout << ans;
}


Error: 210

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define boost                                                                  \\
  ios::sync_with_stdio(false);                                                 \\
  cin.tie(0)
#define pb push_back
#define MP make_pair
#define mod 1000000007
#define int long long
signed main() {
  boost;
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  sort(arr, arr + n);
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += arr[i];
  }
  return ans;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

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

#define int long long

using namespace std;

const int N = 2e5 + 10;

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

Error: -11

Fixed submission:

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

#define int long long

using namespace std;

const int N = 2e5 + 10;

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

#include <algorithm>
#include <cmath>
#include <iostream>
using namespace std;
int main() {
  int x, y, c = 0;
  cin >> x >> y;
  int a[x];
  for (int i = 0; i < x; i++) {
    cin >> a[i];
  }

  sort(a, a + x);
  for (int i = 0; i < y; i++) {
    c = c + a[i];
  }
  cout << c;
  return 0;
}

Error: WA

Fixed submission:

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

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

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

int n, k;
int a[1000 + 5];
int sum;
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++)
    cin >> a[i];

  sort(a + 1, a + n + 1);

  for (int i = 1; i <= k; i++)
    sum += a[i];

  cout << sum;
  return 0;
}

Error: WA

Fixed submission:

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

int main() {
  int n, k, sum = 0;
  int a[n + 1];

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

  sort(a + 1, a + n + 1);

  for (int i = 1; i <= k; i++) {
    sum += a[i];
  }

  cout << sum;
  return 0;
}
Problem p02628 (C++) — buggy submission, verdict: Time Limit Exceeded

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0, min = 1001;
  while (k != 0) {
    for (int i = 0; i < n; i++) {
      if (min > arr[i]) {
        min = arr[i];
      }
    }
    sum += min;
    for (int i = 0; i < n; i++) {
      if (min == arr[i]) {
        arr[i] = 1001;
        break;
      }
    }
    k--;
    min = 1002;
  }
  cout << sum;
}

Error: TLE

Fixed submission:

#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int arr[n];
  for (int i = 0; i < n; i++)
    cin >> arr[i];
  int sum = 0, min = 1001;
  while (k != 0) {
    for (int i = 0; i < n; i++) {
      if (min > arr[i]) {
        min = arr[i];
      }
    }
    sum += min;
    for (int i = 0; i < n; i++) {
      if (min == arr[i]) {
        arr[i] = 1001;
        break;
      }
    }
  }
  cout << sum;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <iostream>
using namespace std;
void so(int n, int *p) {
  for (int i = 0; i < n; i++) {
    for (int j = i + 1; j < n; j++) {
      if (p[i] > p[j]) {
        int t = p[i];
        p[i] = p[j];
        p[j] = t;
      }
    }
  }
}

int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++)
    cin >> p[i];
  so(N, p);
  int c = 0;
  int sum = 0;
  while (K > 0) {
    sum += p[c];
    K--;
    c++;
  }
  cout << sum << endl;
}

Error: -11

Fixed submission:

#include <iostream>
using namespace std;
int main() {
  int N, K;
  cin >> N >> K;
  int p[N];
  for (int i = 0; i < N; i++)
    cin >> p[i];
  int c;
  int sum = 0;
  while (K > 0) {
    int m = p[0];
    for (int i = 0; i < N; i++) {
      if (m > p[i]) {
        m = p[i];
        c = i;
      }
    }
    sum += m;
    p[c] = 1000;
    K--;
  }
  cout << sum << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <iostream>

using namespace std;

int N, K, p[1010];

int main() {
  cin >> N >> K;
  for (int i = 0; i < N; ++i)
    cin >> p[i];
  sort(p, p + N);
  int ans = 0;
  for (int i = 0; i < K; ++i)
    ans += p[i];
  cout << ans << endl;
}

Error: 0

Fixed submission:

#include <algorithm>
#include <iostream>

using namespace std;

int N, K, p[100];

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

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define input1                                                                 \\
  freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
const ll nax = 1e9 + 7;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}

int main() {
  // input1;

  solve();
  return 0;
}

Error: -6
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc


Fixed submission:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define input1                                                                 \\
  freopen("input.txt", "r", stdin); // freopen("output.txt", "w", stdout);
const ll nax = 1e9 + 7;

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> a;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  sort(a.begin(), a.end());
  int ans = 0;
  for (int i = 0; i < k; i++) {
    ans += a[i];
  }
  cout << ans;
}

int main() {
  input1;

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

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

vector<int> p;

void QS(int a, int b) {
  if (b - a <= 1) {
    if (p.at(b) < p.at(a)) {
      swap(p.at(b), p.at(a));
    }
    return;
  }
  int P = (p.at(a) + p.at(b)) / 2;
  int i = a, j = b;
  int X, Y;
  while (true) {
    while (i < j) {
      if (p.at(i) > P) {
        break;
      }
      i++;
    }
    while (i < j) {
      if (p.at(j) <= P) {
        break;
      }
      j--;
    }
    if (i == j) {
      X = j - 1, Y = j;
    } else if (j - i == 1) {
      swap(p.at(i), p.at(j));
      X = i, Y = j;
    } else {
      swap(p.at(i), p.at(j));
      continue;
    }
    break;
  }
  if (X - a <= 1) {
    if (p.at(X) < p.at(a)) {
      swap(p.at(X), p.at(a));
    }
  } else {
    QS(a, X);
  }
  if (b - Y <= 1) {
    if (p.at(b) < p.at(Y)) {
      swap(p.at(b), p.at(Y));
    }
  } else {
    QS(Y, b);
  }
  return;
}

int main() {
  int N, K, Z = 0;
  cin >> N >> K;
  p.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  QS(0, N - 1);
  for (int i = 0; i < K; i++) {
    Z += p.at(i);
  }
  cout << Z << endl;
}


Error: WA

Fixed submission:

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

vector<int> p;

void QS(int a, int b) {
  if (b - a <= 1) {
    if (p.at(b) < p.at(a)) {
      swap(p.at(b), p.at(a));
    }
    return;
  }
  int c = (a + b) / 2;
  int P = (p.at(a) + p.at(b) + p.at(c)) / 3;
  int i = a, j = b;
  int X, Y;
  while (true) {
    while (i < j) {
      if (p.at(i) >= P) {
        break;
      }
      i++;
    }
    while (i < j) {
      if (p.at(j) < P) {
        break;
      }
      j--;
    }
    if (i == j) {
      X = i, Y = i + 1;
    } else if (j - i == 1) {
      swap(p.at(i), p.at(j));
      X = i, Y = j;
    } else {
      swap(p.at(i), p.at(j));
      i++, j--;
      continue;
    }
    break;
  }
  if (X - a <= 1) {
    if (p.at(X) < p.at(a)) {
      swap(p.at(X), p.at(a));
    }
  } else {
    QS(a, X);
  }
  if (b - Y <= 1) {
    if (p.at(b) < p.at(Y)) {
      swap(p.at(b), p.at(Y));
    }
  } else {
    QS(Y, b);
  }
  return;
}

int main() {
  int N, K, Z = 0;
  cin >> N >> K;
  p.resize(N);
  for (int i = 0; i < N; i++) {
    cin >> p.at(i);
  }
  QS(0, N - 1);
  for (int i = 0; i < K; i++) {
    Z += p.at(i);
  }
  cout << Z << endl;
}
Problem p02628 (C++) — buggy submission, verdict: Runtime Error

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

Error: WA

Fixed submission:

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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