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>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
using namespace std;
const int N = 2e5 + 10;
int h[N], a[N], b[N];
int main() {
#define task ""
cin.tie(0) -> sync_with_stdio(0);
// if (fopen ("task.inp", "r")) {
// freopen ("task.inp", "r", stdin);
// freopen ("task.out", "w", stdout);
// }
// if (fopen (task".inp", "r")) {
// freopen (task".inp", "r", stdin);
// freopen (task".out", "w", stdout);
// }
int n; cin >> n;
for(int i = 1; i <= n; i++) cin >> h[i] >> a[i] >> b[i];
int q; cin >> q;
while (q--) {
int l, r; cin >> l >> r;
int ans = -1;
for(int i = l; i <= r; i++) for(int j = i + 1; j <= r; j++) {
int dist = j - i;
if (a[i] <= dist && dist <= b[i] && a[j] <= dist && dist <= b[j]) ans = max(ans, abs(h[i] - h[j]));
}
cout << ans << endl;
}
}
# | 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... |