#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define FOR(i,l,r) for(int i = (l), _r = (r); i <= _r; i++)
#define FORNG(i,r,l) for(int i = (r), _l = (l); i >= _l; i--)
#define REP(i,r) for(int i = 0, _r = (r); i < _r; i++)
#define endl '\n'
#define fi first
#define se second
#define pb push_back
#define size(v) ((ll)(v).size())
#define all(v) (v).begin(),(v).end()
#define MASK(x) (1LL << (x))
#define BIT(x,i) (((x) >> (i)) & 1)
const ll MOD = 1e9 + 7, N = 6e5 + 36, LOG = 18;
const ll INF = 1e18 + 36;
int n,q,h[N],a[N],b[N];
int main(){
//freopen(".INP", "r", stdin);
//freopen(".OUT", "w", stdout);
ios_base::sync_with_stdio(0);cin.tie(0);
cin>>n;
FOR(i,1,n)cin>>h[i]>>a[i]>>b[i];
cin>>q;
while(q--){
int l,r;cin>>l>>r;
int ans = -1;
FOR(i,l,r)FOR(j,i+1,r)if(max(a[i], a[j]) <= j - i && j - i <= min(b[i], 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... |