Connection Status:
Competition Arena > Submission #30
System Testing
9 / 95
WA 9/95 test cases passed
Submission #30
ProblemCutSticks
HandleNur Ahmad Khatim
Submitted2026-07-29 04:12:26
System Messages
Test case #9
Input:    {528, 530, 545, 525, 594, 568, 545, 528, 676, 787, 522, 544, 526, 525, 758, 4978, 534}
Input:    1
Input:    5
Expected: 676.0
Got:      522
Source Code
#include <vector>

using namespace std;

class CutSticks {
public:
    double maxKth(vector<int> sticks, int C, int K) {
    sort(sticks.begin(), sticks.end(), greater<int>());
    int n = sticks.size();
    int c = 0, k = 0, max_depth = 200;
    double l = 0, r = sticks[0];
    int current_depth = 0;
    double current_max = 0;
    while (l <= r && current_depth < max_depth) {
        double mid = (l + r) / 2;
        c = 0, k = 0;
        for (int i = 0; i < n; i++) {
            k += sticks[i] / mid;
            c += max(0.0, sticks[i] / mid - 1);
        }
        if (c <= C && k >= K) {
            current_max = mid;
            l = mid;
        } else {
            r = mid;
        }
        // cout << "l: " << l << ", r: " << r << ", mid: " << mid << ", c: " << c << ", k: " << k << endl;
        // cout << "current_max: " << current_max << endl;
        // cout << "current_depth: " << current_depth << endl;
        current_depth++;
    }
    return current_max == 0 ? sticks[n - 1] : current_max;
}};