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;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
#define ins insert
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n; cin>>n;
vector<int> h(n + 1), a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++){
cin>>h[i]>>a[i]>>b[i];
}
auto check = [&](int& i, int& k){
return (a[i] <= k && k <= b[i]);
};
int q; cin>>q;
while (q--){
int l, r, out = -1; cin>>l>>r;
for (int i = l; i <= r; i++){
for (int j = i + 1; j <= r; j++){
int dif = j - i;
if (check(i, dif) && check(j, dif)){
out = max(out, abs(h[i] - h[j]));
}
}
}
cout<<((out == -1) ? -1: out)<<"\n";
}
// (i -> j): a[i] <= abs(i - j) <= b[i]
// (j -> i): a[j] <= abs(j - i) <= b[j]
// i <-> j: abs(i - j) є [a[i], b[i]], [a[j], b[j]]
}
# | 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... |