This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 200000;
int N, Q;
int h[MAXN+1];
int a[MAXN+1];
int b[MAXN+1];
int l, r;
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> N;
for (int i = 1; i <= N; i++) {
cin >> h[i] >> a[i] >> b[i];
}
cin >> Q;
for (int i = 0; i < Q; i++) {
cin >> l >> r;
int ans = -1;
for (int j = l; j <= r; j++) {
for (int k = l; k <= r; k++) {
if (j == k) continue;
int dis = abs(j-k);
if (dis >= a[j] && dis <= b[j] && dis >= a[k] && dis <= b[k]) {
ans = max(ans, abs(h[j] - h[k]));
}
}
}
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... |