#include <bits/stdc++.h>
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
pair<long long,pair<int,int> > arr[n+1];
for(int i=1; i<=n; i++) cin >> arr[i].first >> arr[i].second.first >> arr[i].second.second;
int q;
cin >> q;
while(q--){
int a,b;
cin >> a >> b;
long long ans=-1;
for(int i=a; i<=b; i++){
for(int j=i+1; j<=b; j++){
int dif=j-i;
if(arr[i].second.first<=dif&&dif<=arr[i].second.second&&arr[j].second.first<=dif&&dif<=arr[j].second.second){
ans=max(ans,abs(arr[i].first-arr[j].first));
}
}
}
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... |