# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1140302 | goatmar | 송신탑 (IOI22_towers) | C++20 | 0 ms | 0 KiB |
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
vector<int> H;
int N;
void init(int N, vector<int> H) {
::N = N;
::H = H;
}
int max_towers(int L, int R, int D) {
int maxH = 0;
for (int i = L; i <= R; ++i) {
if (H[i] > maxH) {
maxH = H[i];
}
}
int count = 0;
int last = -1;
for (int i = L; i <= R; ++i) {
if (H[i] <= maxH - D) {
if (last == -1 || H[i] >= H[last]) {
last = i;
count++;
}
}
}
return count;
}
int main() {
// Example usage
init(7, {10, 20, 60, 40, 50, 30, 70});
printf("%d\n", max_towers(1, 5, 10)); // Output: 3
printf("%d\n", max_towers(2, 2, 100)); // Output: 1
printf("%d\n", max_towers(0, 6, 17)); // Output: 2
return 0;
}