Submission #111772

#TimeUsernameProblemLanguageResultExecution timeMemory
111772mechfrog88Two Antennas (JOI19_antennas)C++14
2 / 100
3022 ms4608 KiB
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef long double ld;

struct tower{
	ll h;
	ll a,b;
};

int main(){
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);
	ll n;
	cin >> n;
	vector <tower> arr(n+1);
	for (int z=0;z<n;z++){
		tower temp;
		cin >> temp.h >> temp.a >> temp.b;
		arr[z+1] = temp;
	}
	ll q;
	cin >> q;
	for (int z=0;z<q;z++){
		ll a,b;
		cin >> a >> b;
		ll ans = -1;
		for (int x=a;x<=b;x++){
			for (int y=x+arr[x].a;y<=x+arr[x].b && y <= b;y++){
				if ( y <= x + arr[x].b && y >= x + arr[x].a &&
					 x >= y - arr[y].b && x <= y - arr[y].a)
					ans = max(ans,abs(arr[x].h-arr[y].h));
			}
		}
		cout << ans << endl;
	}
	cin >> q;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...