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 <iostream>
using namespace std;
typedef long long ll;
int main () {
    int n;cin >> n;
    int height[n + 1]; bool con[n + 1][n + 1];
    for(int i = 0;i <= n;i++)
        for(int j = 0;j <= n;j++)
            con[i][j] = false;
    for(int i = 1,u,v;i <= n;i++){
        cin >> height[i] >> u >> v;
        for(int j = i + u;j <= i + v && j <= n;j++){
            con[i][j] = true;
        }
        for(int j = i - u;j >= 0 && j >= i - v;j--){
            con[i][j] = true;
        }
    }
    int q; cin >> q;
    for(int p = 0;p < q;p++){
        int u,v;
        cin >> u >> v;
        int ans = -1;
        for(int i = u;i <= v;i++){
            for(int j = u;j <= v;j++){
                if(con[i][j] && con[j][i]){
              //      cout << i <<  " " << j << " " << height[i] << " " << height[j] << " " << height[i] - height[j] << endl;
                    ans = max(ans, abs(height[i] - height[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... |