Problem:
Pilling Blocks
We make a tower by stacking up blocks. The tower consists of several stages and each stage is constructed by connecting blocks horizontally. Each block is of the same weight and is tough enough to withstand the weight equivalent to up to $K$ blocks without crushing.
We have to build the tower abiding by the following conditions:
Every stage of the tower has one or more blocks on it.
Each block is loaded with weight that falls within the withstanding range of the block. The weight loaded on a block in a stage is evaluated by: total weight of all blocks above the stage divided by the number of blocks within the stage.
Given the number of blocks and the strength, make a program to evaluate the maximum height (i.e., stages) of the tower than can be constructed.
Input
The input is given in the following format.
$N$ $K$
The input line provides the number of blocks available $N$ ($1 \leq N \leq 10^5$) and the strength of the block $K$ ($1 \leq K \leq 10^5$).
Output
Output the maximum possible number of stages.
Sample Input 1
4 2
Sample Output 1
3
Sample Input 2
5 2
Sample Output 2
4

Submitted solutions:

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	ll N, K;
	cin >> N >> K;
	
	ll ok = 1, ng = N + 10;
	while (ng - ok > 1) {
		ll mid = (ok + ng) / 2;
		
		ll cnt = 0;
		rep(i, 0, mid) {
			ll need = (cnt + K - 1) / K;
			if (need == 0) need = 1;
			cnt += need;
			if (cnt > N) break;
		}
		if (cnt <= N) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}
accuracy: 1
time_ms: 10
memory_kb: 3360
final_rank: 3

code_snippet: #include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, e) for (int i = (int)(s); i < (int)(e); ++i)

int main() {
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	
	int N, K;
	cin >> N >> K;
	
	int ok = 1, ng = N + 10;
	while (ng - ok > 1) {
		int mid = (ok + ng) / 2;
		
		int cnt = 0;
		rep(i, 0, mid) {
			int need = (cnt + K - 1) / K;
			if (need == 0) need = 1;
			cnt += need;
		}
		if (cnt <= N) ok = mid;
		else ng = mid;
	}
	cout << ok << '\n';
}
accuracy: 0.7
time_ms: 10
memory_kb: 3428
final_rank: 7

code_snippet: #include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <cstdint>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <fstream>
#include <cmath>
#include <limits>
#include <chrono>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
#include <cassert>
#include <random>
using namespace std;
using ll = long long;

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

int main() {
    ll n, k;
    cin >> n >> k;
    ll ok = 0;
    ll ng = 2000000;
    while (ng - ok > 1) {
        ll mid = (ok + ng) / 2;
        ll s = 0;
        ll t = 1;
        for (int i = 1; i < mid; i++) {
            t += (t + k - 1) / k;
            if (t > n) {
                s = 1;
                break;
            }
        }
        if (s == 1)ng = mid;
        else ok = mid;
    }
    cout << ok << endl;
}
accuracy: 1
time_ms: 20
memory_kb: 3432
final_rank: 5

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, k;
    cin >> n >> k;
    int ok = 0, ng = n + 10, mid;
    auto f = [&](int N){
        ll s = 1;
        for(int i = 1; i < N; i++){
            s = min(1ll << 60, s + (s + k - 1) / k);
        }
        return (s <= n);
    };
    while(ok + 1 < ng){
        mid = (ok + ng) / 2;
        if(f(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
accuracy: 1
time_ms: 10
memory_kb: 3440
final_rank: 4

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
    int n, k;
    cin >> n >> k;
    int ok = 0, ng = n + 10, mid;
    auto f = [&](int N){
        ll s = 1;
        for(int i = 1; i < N; i++){
            s += (s + k - 1) / k;
        }
        return (s <= n);
    };
    while(ok + 1 < ng){
        mid = (ok + ng) / 2;
        if(f(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
accuracy: 0.7
time_ms: 10
memory_kb: 3440
final_rank: 8

code_snippet: #include<bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T> struct fenwick_tree {
    using U = T;

  public:
    fenwick_tree() : _n(0) {}
    fenwick_tree(int n) : _n(n), data(n) {}

    void add(int p, T x) {
        assert(0 <= p && p < _n);
        p++;
        while (p <= _n) {
            data[p - 1] += U(x);
            p += p & -p;
        }
    }

    T sum(int l, int r) {
        assert(0 <= l && l <= r && r <= _n);
        return sum(r) - sum(l);
    }

  private:
    int _n;
    std::vector<U> data;

    U sum(int r) {
        U s = 0;
        while (r > 0) {
            s += data[r - 1];
            r -= r & -r;
        }
        return s;
    }
};

int main(){
    int n, k;
    cin >> n >> k;
    int ok = 0, ng = n + 1, mid;
    auto f = [&](int N){
        fenwick_tree<ll> fw(N);
        fw.add(0, 1);
        for(int i = 1; i < N; i++){
            ll v = fw.sum(0, i);
            fw.add(i, (v + k - 1) / k);
        }
        return (fw.sum(0, N) <= n);
    };
    while(ok + 1 < ng){
        mid = (ok + ng) / 2;
        if(f(mid))ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
accuracy: 0.7
time_ms: 30
memory_kb: 4136
final_rank: 9

code_snippet: #include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

bool valid(int N, int K, int x) {
  int wsum = 1;
  for (int i = 1; i < x; ++i) {
    int n = (wsum+K-1) / K;
    wsum += n;
    if (wsum > N) return false;
  }
  return wsum <= N;
}

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

  int lb = 1;
  int ub = N+1;
  while (ub-lb > 1) {
    int mid = (lb+ub) >> 1;
    (valid(N, K, mid)? lb:ub) = mid;
  }
  printf("%d\n", lb);
}
accuracy: 1
time_ms: 10
memory_kb: 2688
final_rank: 1

code_snippet: #include <cstdio>
#include <vector>
#include <algorithm>
#include <utility>

bool valid(int N, int K, int x) {
  int wsum = 1;
  for (int i = 1; i < x; ++i) {
    int n = (wsum+K-1) / K;
    wsum += n;
  }
  return wsum <= N;
}

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

  int lb = 1;
  int ub = N+1;
  while (ub-lb > 1) {
    int mid = (lb+ub) >> 1;
    (valid(N, K, mid)? lb:ub) = mid;
  }
  printf("%d\n", lb);
}
accuracy: 0.7
time_ms: 10
memory_kb: 2708
final_rank: 6

code_snippet: #include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;
#define int long long int

const int INF = 1000000007;

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

    double sum = 0;
    int hight = 0;
    
    while(1){
        // sum に耐えうる個数のうち, 最小のものを求める
        int l = 0; 
        int r = 100010;
        while(r - l > 1){
            int d = (r + l) / 2;
            
            double w = INF;
            if(d != 0) w = sum / d;
            if(w <= k) r = d;
            else l = d;
        }

        if(r <= n){
            hight++;
            n -= r;
            sum += r;
        }else{
            cout << hight << endl;
            return 0;
        }
    }
    return 0;
}
accuracy: 1
time_ms: 10
memory_kb: 3092
final_rank: 2