#include <vector>
using namespace std;
vector<int> height;
int n, k;
void init(int kk, std::vector<int> r) {
    n = r.size();
    k = kk;
    height.assign(n, 0);
    vector<int> rr = r;
    vector<bool> used(n, false);
    for (int h = n; h >= 1; --h) {
        int idx = -1;
        for (int i = 0; i < n; ++i) {
            if (used[i]) continue;
            if (rr[i] == 0) {
                bool ok = true;
                for (int j = 1; j < k; ++j) {
                    int prev = (i - j + n) % n;
                    if (!used[prev] && rr[prev] == 0) {
                        ok = false;
                        break;
                    }
                }
                if (ok) {
                    idx = i;
                    break; // always pick the smallest such index
                }
            }
        }
        if (idx == -1) break; // should not happen for valid input
        height[idx] = h;
        used[idx] = true;
        for (int j = 0; j < k; ++j) {
            int prev = (idx - j + n) % n;
            if (!used[prev])
                rr[prev]--;
        }
    }
}
int compare_plants(int x, int y) {
    if (height[x] > height[y]) return 1;
    if (height[x] < height[y]) return -1;
    return 0;
}
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict  | Execution time | Memory | Grader output | 
|---|
| Fetching results... |