prithivMLmods/Coder-Stat huggingface dataset:
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define db double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 1e18
#define eps 0.000001
#define endl '\n'
int main() {
  fastio;
  // #ifndef ONLINE_JUDGE
  freopen("input.txt", "rt", stdin);
  freopen("output.txt", "wt", stdout);
  // #endif
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll x = 0, f = 0;
  for (ll i = 0; i < n; i++) {
    x++;
    if (x == k) {
      f++;
      i--;
      x = 0;
    }
  }
  if (x != 1)
    f++;
  cout << f;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define fastio                                                                 \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define ll long long int
#define ull unsigned long long int
#define db double
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int, int>
#define pdd pair<double, double>
#define pll pair<long long int, long long int>
#define vpl vector<pll>
#define vll vector<ll>
#define mod 1000000007
#define inf 1e18
#define eps 0.000001
#define endl '\n'
int main() {
  fastio;
  // #ifndef ONLINE_JUDGE
  // freopen("input.txt", "rt", stdin);
  // freopen("output.txt", "wt", stdout);
  // #endif
  ll n, k;
  cin >> n >> k;
  ll a[n];
  for (ll i = 0; i < n; i++)
    cin >> a[i];
  ll x = 0, f = 0;
  for (ll i = 0; i < n; i++) {
    x++;
    if (x == k) {
      f++;
      i--;
      x = 0;
    }
  }
  if (x != 1)
    f++;
  cout << f;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

const ll INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;

  // 最小値は1＝＞1を全体に広げていく
  ll count = (N - K + K - 2) / (K - 2) + 1;
  cout << count << endl;
  return 0;
}

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

const ll INF = 1LL << 60;

int main() {
  ll N, K;
  cin >> N >> K;

  // 最小値は1＝＞1を全体に広げていく
  ll count = (N - K + K - 2) / (K - 1) + 1;
  cout << count << endl;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

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

  int n, k;
  cin >> n >> k;

  int a[n];
  int MIN = MOD;
  REP(i, n) {
    cin >> a[i];
    MIN = min(MIN, a[i]);
  }

  vector<int> index;
  REP(i, n) {
    if (a[i] == MIN)
      index.push_back(i);
  }

  int ans = 0;
  int h = index[0];
  while (h > 0) {
    ans++;
    h -= k - 1;
  }

  h = index[0];
  int i = 1;
  while (h < n - 1) {
    ans++;
    h += k - 1;
    while (h >= index[i])
      i++;
    while (index[i] == h + 1) {
      h++;
      i++;
      if (i == index.size())
        break;
    }
  }

  cout << ans << endl;

  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i, a, b) for (long long i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ITR(itr, mp) for (auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x) cout << #x << " = " << (x) << endl;
#define debug(x)                                                               \
  cout << #x << " = " << (x) << " (L" << __LINE__ << ")"                       \
       << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<P> Graph;

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

  int n, k;
  cin >> n >> k;

  cout << ceil((double)(n - 1) / (k - 1)) << endl;

  return 0;
}
Problem p03317 (Python)

Buggy submission (status: Runtime Error):
n, k = map(int, input())
print(((n - 1) + (k - 2)) // (k - 1))


Fixed submission:
n, k = map(int, input().split())
print(((n - 1) + (k - 2)) // (k - 1))
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI; // VI a(n);
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VVI; // VVI a(n,vector<int>(m)) n * m
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<int, int>> PS;
typedef long long ll; // ll とdoubleは違う
// stack<int> st;
//  cout << << endl;
//  cin >> ;
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  ll x = -10, y = -10, d = 0, n, m, h, w, k, max = -100000, min = 10000000,
     ans = 0, count = 1, sum = 0;
  string s;
  cin >> n >> k;
  VI a(n);
  rep(i, n) { cin >> a[i]; }
  sort(ALL(a));
  int i = 0;
  while (a[n - 1] != 1) {
    m = k;
    while (m > 0) {
      a[i] = 1;
      i++;
      m--;
    }
    ans++;
    i--;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include "bits/stdc++.h"
using namespace std;
#define INF 1000000000
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) (x).begin(), (x).end()    // 昇順
#define RALL(x) (x).rbegin(), (x).rend() // 降順
const long long mod = 1e9 + 7;
typedef priority_queue<int> PQ;
typedef vector<long long> Vl;
typedef vector<int> VI; // VI a(n);
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VI> VVI; // VVI a(n,vector<int>(m)) n * m
typedef vector<Vl> VVl;
typedef pair<int, int> PII;
typedef map<int, int> MP; // MP a;
typedef vector<pair<int, int>> PS;
typedef long long ll; // ll とdoubleは違う
// stack<int> st;
//  cout << << endl;
//  cin >> ;
template <typename T> // operator << (cout,a);
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}
template <typename T> T gcd(T a, T b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
  ll x = -10, y = -10, d = 0, n, m, h, w, k, max = -100000, min = 10000000,
     ans = 0, count = 1, sum = 0;
  string s;
  cin >> n >> k;
  VI a(n);
  rep(i, n) { cin >> a[i]; }
  sort(ALL(a));
  int i = 0;
  while (a[n - 1] != 1) {
    m = k;
    while (m > 0 && n > i) {
      a[i] = 1;
      i++;
      m--;
    }
    ans++;
    i--;
  }
  cout << ans << endl;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
// -> limitless <- //
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define read(n) scanf("%d", &n)
using namespace std;
typedef unsigned long long ll;
const int N = 1e4 + 2;
const int mod = 1e9 + 7;

int main() {
  int n, k, mn = 1e9, c = 0, mx = -1;
  read(n), read(k);
  int arr[N] = {};
  lp(i, n) { scanf("%d", arr + i); }
  printf("%d", (int)ceil((n - 1) * 1.0 / (k - 1) * 1.0));
  return 0;
}


Fixed submission:
// -> limitless <- //
#include <bits/stdc++.h>
#define IO ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)
#define lp(i, n) for (int i = 0; i < (int)(n); ++i)
#define read(n) scanf("%d", &n)
using namespace std;
typedef unsigned long long ll;
const int N = 1e4 + 2;
const int mod = 1e9 + 7;

int main() {
  int n, k, mn = 1e9, c = 0, mx = -1;
  read(n), read(k);
  // int arr[N] = {};
  // lp(i, n){scanf("%d", arr + i);}
  printf("%d", (int)ceil((n - 1) * 1.0 / (k - 1) * 1.0));
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  int A[N];
  int min = INT_MAX;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (min > A[i])
      min = A[i];
  }
  int i = 0;
  int count = 0;
  while (i < N) {
    for (int j = i; j < K + i; j++) {
      if (A[j] != min) {
        count++;
      }
    }
    if (count == K) {
      i--;
      sum++;
    } else
      sum++;
    // cout << "count = " << count << endl;

    count = 0;

    i += K;
    // cout << "i = " << i << endl;
  }

  /*if (N == K)
  {
      cout << N / K;
      return 0;
  }
  int p = N / K;
  int sum = p + p;
 */
  cout << sum;

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
#define ll long long int

int main() {
  int N, K;
  cin >> N >> K;
  int sum = 0;
  int A[N];
  int min = INT_MAX;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (min > A[i])
      min = A[i];
  }
  int i = 0;
  int count = 0;
  while (i < N) {
    for (int j = i; j < K + i; j++) {
      if (j > N)
        break;
      if (A[j] != min) {
        count++;
      }
    }
    if (count == K) {
      i--;
      sum++;
    } else
      sum++;
    // cout << "count = " << count << endl;

    count = 0;

    i += K;
    // cout << "i = " << i << endl;
  }

  /*if (N == K)
  {
      cout << N / K;
      return 0;
  }
  int p = N / K;
  int sum = p + p;
 */
  cout << sum;

  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
void solve() {

  long long int a, b, c, d, i, j, k, l;
  cin >> a >> b;
  int a1[a];
  for (i = 0; i < a; i++)
    cin >> a1[i];
  a = a - b;
  b = b - 1;

  int ans = ceil((double)a / b);
  //<<ans;
  cout << ans + 1;
}
int main() {
  int k = 4;
  while (k--)
    solve();
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
void solve() {

  long long int a, b, c, d, i, j, k, l;
  cin >> a >> b;
  int a1[a];
  for (i = 0; i < a; i++)
    cin >> a1[i];
  a = a - b;
  b = b - 1;

  int ans = ceil((double)a / b);
  //<<ans;
  cout << ans + 1;
}
int main() {
  int k = 4;
  // while(k--)
  solve();
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;

int main() {
  int x, y;
  cout << (x - 1) % y + 1 << endl;
}


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

int main() {
  int x, y;
  cin >> x >> y;
  cout << (x - 2) / (y - 1) + 1 << endl;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
// Shift-JIS（シフトジス）

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

int gcd(int a, int b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  int N, K;
  cin >> N >> K;
  int A;
  for (int i = 0; i < N; i++)
    cin >> A;
  cout << ((N - 1) / (K - 1 - 1)) / (K - 1) << endl;
}

Fixed submission:
// Shift-JIS（シフトジス）

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

int gcd(int a, int b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

int lcm(int a, int b) { return a * b / gcd(a, b); }

int main() {
  int N, K;
  cin >> N >> K;
  int A;
  for (int i = 0; i < N; i++)
    cin >> A;
  cout << ((N - 1) + (K - 1 - 1)) / (K - 1) << endl;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m;
  int num[10000];
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> num[i];
  int t = n / m;
  while ((t * m) < n + t - 1) {
    t++;
  }
  cout << t << endl;
  return 0;
}

Fixed submission:
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int main() {
  int n, m;
  int num[100005];
  cin >> n >> m;
  for (int i = 0; i < n; i++)
    cin >> num[i];
  int t = n / m;
  while ((t * m) < n + t - 1) {
    t++;
  }
  cout << t << endl;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c = 0;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < n; i++)
    if (a[i] != 1) {
      int g = i - 1;
      for (int j = i - 1; j < k + (i - 1); j++) {
        a[j] = 1;
        g = j;
      }
      i = g;
      c++;
    }
  cout << c;
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, c = 0;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++)
    cin >> a[i];
  for (int i = 0; i < (n - 1); i += (k - 1)) {
    c++;
  }
  cout << c;
}
Problem p03317 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K, ans = 0, t = 0;
  cin >> N >> K;
  while (t < N) {
    ans++;
    t = (K - 1) + 1;
  }
  cout << ans << endl;
  return 0;
}

Fixed submission:
#include <algorithm>
#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <vector>
using namespace std;
using ll = long long;
map<int, int> mpa, mpb;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int N, K, ans = 0, t = 0;
  cin >> N >> K;
  while (t < N) {
    ans++;
    t = (K - 1) * ans + 1;
  }
  cout << ans << endl;
  return 0;
}
Problem p03317 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  int N, K;
  int A[10000];

  cin >> N >> K;

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

  int Ans;

  if ((N - 1) % (K - 1) == 0) {
    Ans = (N - 1) / (K - 1);
  } else
    Ans = (N - 1) / (K - 1) + 1;

  cout << Ans;

  return 0;
}

Fixed submission:
#include <algorithm>
#include <functional>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <vector>

using namespace std;
int main() {
  int N, K;
  int A[10000];

  cin >> N >> K;

  int Ans;

  if ((N - 1) % (K - 1) == 0) {
    Ans = (N - 1) / (K - 1);
  } else
    Ans = (N - 1) / (K - 1) + 1;

  cout << Ans;

  return 0;
}
Problem p03318 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int Digit_Sum(int n) {
  int Cmp = 0;
  while (n) {
    Cmp += n % 10;
    n /= 10;
  }
  return Cmp;
}
double Value(int n) { return (double)n / Digit_Sum(n); }
int Digit(int n) {
  int Cmp = 0;
  while (n) {
    n /= 10;
    Cmp++;
  }
  return Cmp;
}
signed main() {
  int k, Cnt = 0;
  double Max = -1, Min = INF;
  cin >> k;
  // double KVal = (double)k / Digit_Sum(k);
  // for (int i = 9; i < 20000; i += 10) {
  // 	cout << i << " " << Value(i) << endl;
  // 	Max = max(Max, Value(i));
  // 	Min = min(Min, Value(i));
  // }
  // cout << endl << Max << " " << Min << endl;
  if (k <= 9) {
    for (int i = 1; i <= k; i++) {
      cout << i << endl;
    }
    return 0;
  }
  for (int i = 1; i <= 9; i++) {
    cout << i << endl;
  }
  int Cnt2 = 9, Cmp = 9;
  while (Cnt2 < k) {
    int CMP = pow(10, Digit(Cmp));
    for (int i = 0; i < k - Cnt2; i++) {
      cout << Cmp + CMP << endl;
      Cmp += CMP;
    }
  }
  return 0;
}

Fixed submission:
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
int Digit_Sum(int n) {
  int Cmp = 0;
  while (n) {
    Cmp += n % 10;
    n /= 10;
  }
  return Cmp;
}
double Value(int n) { return (double)n / Digit_Sum(n); }
int Digit(int n) {
  int Cmp = 0;
  while (n) {
    n /= 10;
    Cmp++;
  }
  return Cmp;
}
signed main() {
  int k, Cnt = 0;
  double Max = -1, Min = INF;
  cin >> k;
  // double KVal = (double)k / Digit_Sum(k);
  // for (int i = 9; i < 20000; i += 10) {
  // 	cout << i << " " << Value(i) << endl;
  // 	Max = max(Max, Value(i));
  // 	Min = min(Min, Value(i));
  // }
  // cout << endl << Max << " " << Min << endl;
  if (k <= 9) {
    for (int i = 1; i <= k; i++) {
      cout << i << endl;
    }
    return 0;
  }
  int Ans = 1, Cmp = 1;
  for (int i = 0; i < k; i++) {
    cout << Ans << endl;
    while (Value(Ans + Cmp) > Value(Ans + 2 * Cmp))
      Cmp *= 10;
    Ans += Cmp;
  }
  return 0;
}
Problem p03318 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;

float calc_sd(ll n) {
  string temp = std::to_string(n);
  int sn = 0;
  for (int i = 0; i < temp.length(); i++) {
    char tt[2];
    tt[0] = temp[i];
    tt[1] = NULL;
    sn = sn + atoi(tt);
  }
  float retval = 0;
  retval = (float)n / (float)sn;
  return retval;
}

bool if_sunuke(int sunuke) {
  for (int i = sunuke + 1; i < sunuke * 10; i++) {
    if (calc_sd(sunuke) > calc_sd(i))
      return false;
  }
  return true;
}

int main(void) {
  ll res = 1;
  ll pls = 1;
  int count = 1;
  int k;
  cin >> k;
  cout << 1 << endl;
  while (count < k) {
    while (calc_sd(res + pls + pls) < calc_sd(res + pls))
      pls = pls * 10;
    res = res + pls;
    cout << res << endl;
  }
}


Fixed submission:
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long int ll;

float calc_sd(ll n) {
  string temp = std::to_string(n);
  int sn = 0;
  for (int i = 0; i < temp.length(); i++) {
    char tt[2];
    tt[0] = temp[i];
    tt[1] = NULL;
    sn = sn + atoi(tt);
  }
  float retval = 0;
  retval = (float)n / (float)sn;
  return retval;
}

bool if_sunuke(int sunuke) {
  for (int i = sunuke + 1; i < sunuke * 10; i++) {
    if (calc_sd(sunuke) > calc_sd(i))
      return false;
  }
  return true;
}

int main(void) {
  ll res = 1;
  ll pls = 1;
  int count = 1;
  int k;
  cin >> k;
  cout << 1 << endl;
  while (count < k) {
    while (calc_sd(res + pls + pls) < calc_sd(res + pls))
      pls = pls * 10;
    res = res + pls;
    cout << res << endl;
    count++;
  }
}
Problem p03318 (C++)

Buggy submission (status: Time Limit Exceeded):
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 1e6 + 60;
int sum(int x) {
  int r = 0;
  for (; x; x /= 10)
    r += x % 10;
  return r;
}
int main() {
  int k;
  scanf("%d", &k);
  ll ans = 0, x = 1;
  for (int i = 0; i < k; i++) {
    while ((ans + x) * sum(ans + x * 10) >= (ans + x * 10) * sum(ans + x))
      x *= 10;
    ans += x;
    printf("%lld\n", ans);
  }
  return 0;
}

Fixed submission:
#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
using namespace std;
#define CRP(t, x) const t &x
#define OPL(t, x) bool operator<(CRP(t, x)) const
#define FIL(x, v) memset(x, v, sizeof(x))
#define CLR(x) FIL(x, 0)
#define NE1(x) FIL(x, -1)
#define INF(x) FIL(x, 0x3f)
#ifndef _DEBUG
#define _DEBUG 0
#endif // !_DEBUG
#define IFD if (_DEBUG)
typedef long long ll, i64;
const int N = 1e6 + 60;
int sum(ll x) {
  int r = 0;
  for (; x; x /= 10)
    r += x % 10;
  return r;
}
int main() {
  int k;
  scanf("%d", &k);
  ll ans = 0, x = 1;
  for (int i = 0; i < k; i++) {
    while ((ans + x) * sum(ans + x * 10) >= (ans + x * 10) * sum(ans + x))
      x *= 10;
    ans += x;
    printf("%lld\n", ans);
  }
  return 0;
}
Problem p03318 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using ll = long long;

// 各桁の数の和
int digitSum(int x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

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

  int k;
  cin >> k;

  vector<ll> x;
  for (ll i = 0; i < 15; i++) {
    ll keep = pow(10, i);
    for (ll j = 1; j <= 999; j++) {
      x.emplace_back(keep * j + keep - 1);
    }
  }

  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());

  vector<bool> judge(x.size(), true);
  for (int i = 0; i < x.size() - 1; i++) {
    for (int j = i + 1; j < x.size(); j++) {
      if ((double)x.at(i) / digitSum(x.at(i)) >
          (double)x.at(j) / digitSum(x.at(j))) {
        judge.at(i) = false;
        break;
      }
    }
  }

  int it = 0;
  for (int i = 0; i < k; i++) {
    while (!judge.at(it))
      it++;
    cout << x.at(it) << '\n';
    it++;
  }
}

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

using ll = long long;

// 各桁の数の和
int digitSum(ll x) {
  int sum = 0;
  while (x > 0) {
    sum += x % 10;
    x /= 10;
  }
  return sum;
}

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

  int k;
  cin >> k;

  vector<ll> x;
  for (ll i = 0; i < 15; i++) {
    ll keep = pow(10, i);
    for (ll j = 1; j <= 999; j++) {
      x.emplace_back(keep * j + keep - 1);
    }
  }

  sort(x.begin(), x.end());
  x.erase(unique(x.begin(), x.end()), x.end());

  vector<bool> judge(x.size(), true);
  for (int i = 0; i < x.size() - 1; i++) {
    for (int j = i + 1; j < x.size(); j++) {
      if ((double)x.at(i) / digitSum(x.at(i)) >
          (double)x.at(j) / digitSum(x.at(j))) {
        judge.at(i) = false;
        break;
      }
    }
  }

  int it = 0;
  for (int i = 0; i < k; i++) {
    while (!judge.at(it))
      it++;
    cout << x.at(it) << '\n';
    it++;
  }
}
Problem p03319 (Python)

Buggy submission (status: Runtime Error):
n, k = map(int, input().split())
print((n - 2) // (k - 2) + 1)


Fixed submission:
n, k = map(int, input().split())
print((n - 2) // (k - 1) + 1)
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <cstdio>
bool a[110000];
int main(void) {
  int n, k, t, cnt = 0, num = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &t);
  while (a[n - 1] == false) {
    for (int i = cnt; i < cnt + k; i++)
      a[i] = true;
    cnt += k - 1;
    num++;
  }
  printf("%d", num);
  return 0;
}


Fixed submission:
#include <cstdio>
bool a[500000];
int main(void) {
  int n, k, t, cnt = 0, num = 0;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; i++)
    scanf("%d", &t);
  while (a[n - 1] == false) {
    for (int i = cnt; i < cnt + k; i++)
      a[i] = true;
    cnt += k - 1;
    num++;
  }
  printf("%d", num);
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int idx = 0, ans = 0;
  while (idx < n) {
    int tmp_k = k - 1;
    while (tmp_k--) {
      if (A[idx] == 1) {
        tmp_k++;
        idx++;
        continue;
      }
      A[idx] = 1;
      idx++;
    }
    ans++;
  }
  cout << ans << endl;
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}

Fixed submission:
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
using ll = long long;
const int INF = 1 << 30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) {
  for (int i = 0; i < (int)v.size(); i++)
    os << v[i] << (i + 1 != v.size() ? " " : "");
  return os;
}

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    cin >> A[i];
  }

  int idx = 0, ans = 0;
  while (idx < n) {
    int tmp_k = k - 1;
    while (tmp_k--) {
      if (idx >= n)
        break;
      if (A[idx] == 1) {
        tmp_k++;
        idx++;
        continue;
      }
      A[idx] = 1;
      idx++;
    }
    ans++;
  }
  cout << ans << endl;
}

signed main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 1;
const long long INF = 1e13 + 7;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, k, a[N];
int main() {
  scanf("%d %d", &n, &k);
  forn(i, 1, n) { scanf("%d", a + i); }
  if (n == k)
    return printf("1\n");
  printf("%d\n", 1 + (n - k - 1) / (k - 1) + 1);
  return 0;
}


Fixed submission:
// V solo
#include <bits/stdc++.h>

#define forn(i, a, b) for (int i = a; i <= b; ++i)
#define forr(i, a, b) for (int i = a; i >= b; --i)

using namespace std;

const int N = (int)1e5 + 1;
const long long INF = 1e13 + 7;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int n, k, a[N];
int main() {
  scanf("%d %d", &n, &k);
  forn(i, 1, n) { scanf("%d", a + i); }
  if (n == k)
    return printf("1\n"), 0;
  printf("%d\n", 1 + (n - k - 1) / (k - 1) + 1);
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  int n, k;
  cin >> n >> k;
  int temp;
  int count = 0;
  rep(i, n) {
    cin >> temp;
    if (temp == 1) {
      count = i + 1;
    }
  }
  if (count <= k || (n - k <= count && k <= count)) {
    if ((n - k) % (k - 1) != 0)
      cout << (n - k) / (k - 1) + 2 << endl;
    else
      cout << (n - k) / (k - 1) + 1 << endl;
  } else {
    return -1;
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define REP(i, a, b) for (int i = a; i < (b); ++i)
#define mREP(i, a, b) for (int i = a; i > (b); --i)
#define all(x) (x).begin(), (x).end()
const int INF = 1000000007;
typedef long long ll;
using namespace std;
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;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
int main() {
  int n, k;
  cin >> n >> k;
  int temp;
  int count = 0;
  rep(i, n) {
    cin >> temp;
    if (temp == 1) {
      count = i + 1;
    }
  }

  if ((n - k) % (k - 1) != 0)
    cout << (n - k) / (k - 1) + 2 << endl;
  else
    cout << (n - k) / (k - 1) + 1 << endl;

  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;

using i64 = int64_t;

#define rep(i, x, y)                                                           \
  for (i64 i = i64(x), i##_max_for_repmacro = i64(y);                          \
       i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];

  if (N == K) {
    cout << 1 << endl;
    return;
  }

  int ans = 1;
  vector<bool> b(N);
  rep(i, 0, K) b[i] = true;
  rep(i, 0, N) {
    if (i + 1 < N and !b[i + 1]) {
      ++ans;
      rep(j, i, i + K) b[j] = true;
    }
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}


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

using i64 = int64_t;

#define rep(i, x, y)                                                           \
  for (i64 i = i64(x), i##_max_for_repmacro = i64(y);                          \
       i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (const auto &v : vec) {
    os << v << ",";
  }
  os << "]";
  return os;
}

void solve() {
  int N, K;
  cin >> N >> K;

  vector<int> A(N);
  rep(i, 0, N) cin >> A[i];

  if (N == K) {
    cout << 1 << endl;
    return;
  }

  int ans = 1;
  vector<bool> b(N);
  rep(i, 0, K) b[i] = true;
  rep(i, 0, N) {
    if (i + 1 < N and !b[i + 1]) {
      ++ans;
      rep(j, i, i + K) {
        if (j >= N)
          break;
        b[j] = true;
      }
    }
  }

  cout << ans << endl;
}

int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cout.setf(ios::fixed);
  cout.precision(16);
  solve();
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <fstream>
#include <iomanip>
#include <iostream>

#include <bitset>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <algorithm>
#include <numeric>
#include <random>

#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e3) + 17;

int n, k;
int a[MAXN];

bool read() {
  if (!(cin >> n >> k))
    return false;

  forn(i, n) cin >> a[i];

  return true;
}

void solve() {
  int j = -1;

  forn(i, n) if (a[i] == 1) j = i;

  int ans = INF;

  forn(i, n) if (i + k <= n && i <= j && j < i + k) {
    int res = 1;
    int pref = i, suff = n - (i + k);
    res += (pref + k - 2) / (k - 1);
    res += (suff + k - 2) / (k - 1);
    ans = min(ans, res);
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
  freopen("file.in", "r", stdin);
#endif

  while (read())
    solve();

  return 0;
};


Fixed submission:
#include <fstream>
#include <iomanip>
#include <iostream>

#include <bitset>
#include <deque>
#include <map>
#include <set>
#include <string>
#include <vector>

#include <algorithm>
#include <numeric>
#include <random>

#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;

int n, k;
int a[MAXN];

bool read() {
  if (!(cin >> n >> k))
    return false;

  forn(i, n) cin >> a[i];

  return true;
}

void solve() {
  int j = -1;

  forn(i, n) if (a[i] == 1) j = i;

  int ans = INF;

  forn(i, n) if (i + k <= n && i <= j && j < i + k) {
    int res = 1;
    int pref = i, suff = n - (i + k);
    res += (pref + k - 2) / (k - 1);
    res += (suff + k - 2) / (k - 1);
    ans = min(ans, res);
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

#ifdef SEREZHKA
  freopen("file.in", "r", stdin);
#endif

  while (read())
    solve();

  return 0;
};
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <cmath>
#include <cstdio>

int main() {
  int N, K;
  int A;
  int i;
  scanf("%d %d", &N, &K);
  for (i = 0; i < N; i++) {
    scanf("%d", &A);
  }

  int n;
  n = ceil((double)(N - 1) / (K - 1));

  return n;
}

Fixed submission:
#include <cmath>
#include <cstdio>

int main() {
  int N, K;
  int A;
  int i;
  scanf("%d %d", &N, &K);
  for (i = 0; i < N; i++) {
    scanf("%d", &A);
  }

  int n;
  n = ceil((double)(N - 1) / (K - 1));

  printf("%d", n);
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <iostream>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  return (N - 2) / (K - 1) + 1;
}

Fixed submission:
#include <iostream>
using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  cout << (N - 2) / (K - 1) + 1;
  return 0;
}
Problem p03319 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MAXN = 2005;
int n, k, m, pos, ans = 1e9;
int A[MAXN];

int f(int x, int y) {
  if (x > y)
    return 0;
  int d = y - x + 1;
  if (d % m == 0)
    return d / m;
  return d / m + 1;
}

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

  cin >> n >> k;
  m = k - 1;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] == 1) {
      pos = i;
    }
  }

  for (int ile = 1; ile <= k; pos--, ile++)
    ans = min(ans, f(0, pos - 1) + f(pos + k, n - 1));

  cout << ++ans << "\n";

  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
const int MAXN = 1e5 + 5;
int n, k, m, pos, ans = 1e9;
int A[MAXN];

int f(int x, int y) {
  if (x > y)
    return 0;
  int d = y - x + 1;
  if (d % m == 0)
    return d / m;
  return d / m + 1;
}

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

  cin >> n >> k;
  m = k - 1;
  for (int i = 0; i < n; i++) {
    cin >> A[i];
    if (A[i] == 1) {
      pos = i;
    }
  }

  for (int ile = 1; ile <= k; pos--, ile++)
    ans = min(ans, f(0, pos - 1) + f(pos + k, n - 1));

  cout << ++ans << "\n";

  return 0;
}
Problem p03320 (C++)

Buggy submission (status: Runtime Error):
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i, j;
  scanf("%d", &n);
  for (i = 1; i <= n; ++i) {
    int t[15], tn = 0;
    for (j = i; j;)
      j -= t[tn++] = min(j, 9);
    while (tn--)
      printf("%d", t[tn]);
    puts("");
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k;
  long long x = 0;
  scanf("%d", &k);
  while (k--) {
    int y = 0, Y, z[20], zn = 0;
    long long i, X, t = 1;
    for (i = ++x; i; i /= 10)
      y += z[++zn] = i % 10;
    for (X = x, Y = y, i = 1; i <= zn; ++i) {
      X += (9 - z[i]) * t;
      Y += 9 - z[i];
      t *= 10;
      if (x * Y > X * y)
        x = X, y = Y;
    }
    printf("%lld\n", x);
  }
}
Problem p03320 (C++)

Buggy submission (status: Time Limit Exceeded):
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

LL K;
std::vector<LL> ans;

LL f(LL n) {
  LL res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main() {
  in >> K;
  for (LL i = 0; i <= 20; ++i) {
    for (LL j = 1; j <= 10000; ++j) {
      if (i == 0 && j == 1)
        continue;
      LL tmp = j * pow(10LL, i);
      --tmp;
      ans.push_back(tmp);
    }
  }
  std::sort(ans.begin(), ans.end());
  ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
  rep(i, ans.size()) {
    for (int j = i + 1; j < ans.size(); ++j) {
      if ((long double)ans[i] / f(ans[i]) > (long double)ans[j] / f(ans[j])) {
        ans.erase(ans.begin() + i);
        --i;
        break;
      }
    }
  }
  rep(i, K) out << ans[i] << std::endl;
  return 0;
}


Fixed submission:
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i, N) for (int i = 0; i < N; ++i)
typedef long long int LL;

LL K;
std::vector<LL> ans;

LL f(LL n) {
  LL res = 0;
  while (n > 0) {
    res += n % 10;
    n /= 10;
  }
  return res;
}

int main() {
  in >> K;
  for (LL i = 0; i <= 15; ++i) {
    for (LL j = 1; j <= 1000; ++j) {
      if (i == 0 && j == 1)
        continue;
      LL tmp = j * pow(10LL, i);
      --tmp;
      ans.push_back(tmp);
    }
  }
  std::sort(ans.begin(), ans.end());
  ans.erase(std::unique(ans.begin(), ans.end()), ans.end());
  rep(i, ans.size()) {
    for (int j = i + 1; j < ans.size(); ++j) {
      if ((long double)ans[i] / f(ans[i]) > (long double)ans[j] / f(ans[j])) {
        ans.erase(ans.begin() + i);
        --i;
        break;
      }
    }
  }
  rep(i, K) out << ans[i] << std::endl;
  return 0;
}
Problem p03320 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
typedef long long i64;
using std::cin;
using std::cout;
using std::endl;

int s(i64 n) {
  std::string w = std::to_string(n);

  int ret = 0;
  for (int i = 0; i < w.size(); i++)
    ret += w[i] - '0';
  return ret;
}

int main() {
  int k;
  cin >> k;
  const i64 MAX = 1e15;
  std::vector<i64> vec;
  for (i64 i = 0, tmp = 1; i < 15; i++, tmp *= 10) {
    for (int j = 1; j < 1000; j++)
      vec.push_back(tmp * j + tmp - 1);
  }
  sort(begin(vec), end(vec));
  vec.erase(unique(begin(vec), end(vec)), end(vec));

  for (int i = 0; k and i < vec.size(); i++) {
    bool f = true;
    for (int j = i + 1; j < vec.size(); j++) {
      i64 n = vec[i], m = vec[j];
      f &= n * s(m) <= m * s(n);
    }

    if (f) {
      cout << vec[i] << endl;
      k--;
    }
  }
  return 0;
}


Fixed submission:
#include <bits/stdc++.h>
typedef long long i64;
using std::cin;
using std::cout;
using std::endl;

int s(i64 n) {
  std::string w = std::to_string(n);

  int ret = 0;
  for (int i = 0; i < w.size(); i++)
    ret += w[i] - '0';
  return ret;
}

int main() {
  int k;
  cin >> k;
  const i64 MAX = 1e15;
  std::vector<i64> vec;
  for (i64 i = 0, tmp = 1; i < 15; i++, tmp *= 10) {
    for (int j = 1; j < 1000; j++)
      vec.push_back(tmp * j + tmp - 1);
  }
  sort(begin(vec), end(vec));
  vec.erase(unique(begin(vec), end(vec)), end(vec));

  for (int i = 0; k and i < vec.size(); i++) {
    bool f = true;
    for (int j = i + 1; j < vec.size(); j++) {
      i64 n = vec[i], m = vec[j];
      f &= (__int128_t)n * s(m) <= (__int128_t)m * s(n);
      if (!f)
        break;
    }

    if (f) {
      cout << vec[i] << endl;
      k--;
    }
  }
  return 0;
}
Problem p03320 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int s(int x) {
  int res = 0;
  while (x)
    res += x % 10, x /= 10;
  return res;
}

int main() {
  ll k, step = 1, curr = 1;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    while ((curr + 10 * step) * s(curr + step) <=
           (curr + step) * s(curr + 10 * step)) {
      step *= 10;
    }
    cout << curr << '\n';
    curr += step;
  }
}


Fixed submission:
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

int s(ll x) {
  int res = 0;
  while (x)
    res += x % 10, x /= 10;
  return res;
}

int main() {
  ll k, step = 1, curr = 1;
  cin >> k;
  for (int i = 1; i <= k; ++i) {
    while ((curr + 10 * step) * s(curr + step) <=
           (curr + step) * s(curr + 10 * step)) {
      step *= 10;
    }
    cout << curr << '\n';
    curr += step;
  }
}
Problem p03320 (C++)

Buggy submission (status: Time Limit Exceeded):
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
ll s(ll n) {
  ll res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
signed main() {
  ll k;
  cin >> k;
  ll now = 1;
  ll ans = 1;
  while (k) {
    cout << ans << endl;
    ll c = ans + now;
    if (c - now * s(c) <= 0) {
      ans = c;
    } else {
      while (c - now * s(c) > 0) {
        now++;
      }
      ans += now;
    }
    k--;
  }
}

Fixed submission:
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, m, n) for (int i = (m); i < (n); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(c) (c).rbegin(), (c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll>>
#define fi first
#define se second
typedef long long ll;
typedef pair<ll, ll> pll;
typedef long double ld;
const ll inf = 1e9 + 7;
const ll mod = 998244353;
ll s(ll n) {
  ll res = 0;
  while (n) {
    res += n % 10;
    n /= 10;
  }
  return res;
}
signed main() {
  ll k;
  cin >> k;
  ll now = 1;
  ll ans = 1;
  while (k) {
    cout << ans << endl;
    ll c = ans + now;
    if (c - now * s(c) <= 0) {
      ans = c;
    } else {
      while (c - now * s(c) > 0) {
        now *= 10;
      }
      ans += now;
    }
    k--;
  }
}
Problem p03320 (C++)

Buggy submission (status: Runtime Error):
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;

LL k;

bool check(LL n) {
  LL m = n;
  int c[20], tot = 0;
  int digitsum = 0;
  while (n > 0) {
    c[++tot] = n % 10;
    n /= 10;
    digitsum += c[tot];
  }
  // reverse(c + 1, c + 1 + tot);
  LL now = 1;
  for (int i = 1; i <= tot; i++) {
    if (c[i] != 9) {
      break;
    }
    now *= 10;
  }
  if (now * digitsum >= m)
    return true;
  else
    return false;
}

LL power[15];

int main() {
  cin >> k;
  power[0] = 1;
  for (int i = 1; i <= 15; i++) {
    power[i] = power[i - 1] * 10;
  }
  vector<LL> ans;
  for (int i = 1; i < 10000; i++) {
    if (check(i)) {
      ans.push_back(i);
      // cout << i << endl;
    }
  }
  for (int i = 4; i <= 15; i++) {
    for (int j = 100; j < 1000; j++) {
      LL tmp = j * power[i - 3] + (power[i - 3] - 1);
      if (check(tmp)) {
        // cout << tmp << endl;
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < k; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}


Fixed submission:
#include <algorithm>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long LL;

LL k;

bool check(LL n) {
  LL m = n;
  int c[20], tot = 0;
  int digitsum = 0;
  while (n > 0) {
    c[++tot] = n % 10;
    n /= 10;
    digitsum += c[tot];
  }
  // reverse(c + 1, c + 1 + tot);
  LL now = 1;
  for (int i = 1; i <= tot; i++) {
    if (c[i] != 9) {
      break;
    }
    now *= 10;
  }
  if (now * digitsum >= m)
    return true;
  else
    return false;
}

LL power[15];

int main() {
  cin >> k;
  power[0] = 1;
  for (int i = 1; i <= 15; i++) {
    power[i] = power[i - 1] * 10;
  }
  vector<LL> ans;
  for (int i = 1; i < 10000; i++) {
    if (check(i)) {
      ans.push_back(i);
      // cout << i << endl;
    }
  }
  for (int i = 5; i <= 15; i++) {
    for (int j = 100; j < 1000; j++) {
      LL tmp = j * power[i - 3] + (power[i - 3] - 1);
      if (check(tmp)) {
        // cout << tmp << endl;
        ans.push_back(tmp);
      }
    }
  }
  sort(ans.begin(), ans.end());
  for (int i = 0; i < k; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}