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;
#define pb push_back
#define pob pop_back
#define st first
#define nd second
#define test cout<<"test"<<endl;
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;
ll INF = 1e9;
ll mod = 1e9+7;
ll n,m,k,l,r,ans;
ll min(ll a, ll b) {
return (a<b)? a:b;
}
ll max(ll a, ll b) {
return a+b-min(a,b);
}
ll q;
int main() {
//freopen("input","r",stdin);
cin>>n;
vector<pair<ll,pll> > ants;
ants.resize(n);
for(int i=0; i<n; i++) {
cin>>ants[i].st>>ants[i].nd.st>>ants[i].nd.nd;
}
cin>>q;
for(int i=0; i<q; i++) {
cin>>l>>r;
l--;
r--;
m = -1;
for(int j=l; j<=r; j++) {
for(int k=j+1; k<=r; k++) {
if(abs(j-k) >= ants[j].nd.st and abs(j-k) <= ants[j].nd.nd and abs(j-k) <= ants[k].nd.nd and abs(j-k) >= ants[k].nd.st) {
m = max(m , abs(ants[j].st - ants[k].st));
}
}
}
cout<<m<<endl;
}
return 0;
}
# | 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... |