#include <bits/stdc++.h>
int main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> h(n), a(n), b(n);
for (int i = 0; i < n; ++i) {
std::cin >> h[i] >> a[i] >> b[i];
}
auto comm = [&](int i, int j) {
return (i + a[i] <= j and j <= i + b[i]) or
(i - b[i] <= j and j <= i - a[i]);
};
int q;
std::cin >> q;
while (q--) {
int l, r;
std::cin >> l >> r;
--l, --r;
int ans = -1;
for (int i = l; i <= r; ++i) {
for (int j = i + 1; j <= r; ++j) {
if (comm(i, j) and comm(j, i)) {
ans = std::max(ans, std::abs(h[i] - h[j]));
}
}
}
std::cout << ans << '\n';
}
}
# | 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... |