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 pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n; cin >> n;
vector<ll> H(n);
vector<int> A(n), B(n);
for(int i = 0; i < n; i++) cin >> H[i] >> A[i] >> B[i];
int q; cin >> q;
while(q--){
int l, r; cin >> l >> r; l--, r--;
ll ans = -1;
for(int i = l; i <= r; i++) for(int j = i+1; j <= r; j++){
if(j >= i+A[i] && j <= i+B[i] && i >= j-B[j] && i <= j-A[j])
ans = max(ans, abs(H[i]-H[j]));
}
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... |