#include #include #include

using namespace std;

int main() { int n, m; cin >> n >> m;

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

sort(heights.begin(), heights.end(), greater<int>());

int max_height = heights[0];
int total_length = 0;
for (int i = 0; i < n; i++) {
    if (heights[i] <= max_height) {
        total_length += heights[i] - max_height;
        max_height = heights[i];
    } else {
        break;
    }
}

int remain_length = total_length - m;
int ans = max_height - remain_length / n;
cout << ans << endl;

return 0;
描述伐木工小 A 需要砍倒 m 米长的木材。现在他弄到了一个奇怪的伐木机。伐木机工作过程如下:设置一个高度参数 h米伐木机升起一个巨大的锯片到高度 h并锯掉所有的树比 h 高的部分当然树木不高于 h 米的部分保持不变。小 A 就得到树木被锯下的部分。例如如果一行树的高度分别为 20、15、10 和 17 米把锯片升到 15 米的高度切割后树木剩下的高度将是 15、15、10 和 15 米而将从第

原文地址: http://www.cveoy.top/t/topic/iPdW 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录