题解:P13692 [CEOI 2025] lawnmower
Vlad 拥有一台容量为 的割草机,需要按顺序割完 条割草道。每条割草道 有 的草量,经过该道需要 秒。割草机的收集箱容量为 ,当收集箱满时,必须在该道末端清空,清空需要 秒。割草完成后还需清空一次。Vlad 可以选择在任意时刻提前清空收集箱,以优化总时间。
long long mow(int n, int c, int b, std::vector<int> &a, std::vector<int> &v) {
long long total_time = 0;
int current = 0; // 当前收集箱的草量
for (int i = 0; i < n; i++) {
// 割草当前道
total_time += a[i];
current += v[i];
if (current > c) {
// 需要清空
total_time += b;
current = v[i]; // 清空后,当前道的草量为 v[i]
}
}
// 最后清空一次
total_time += b;
return total_time;
}
以上是伪代码...
代码就不占了,以防某些人借鉴