Submission #132043

#TimeUsernameProblemLanguageResultExecution timeMemory
132043KewoTwo Antennas (JOI19_antennas)C++17
2 / 100
3044 ms32504 KiB
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define mid ((x + y) / 2)
#define left (ind * 2)
#define right (ind * 2 + 1)
#define spc " "
#define endl "\n"
#define fast_io() cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(false)
using namespace std;

typedef pair<int, int> ii;
typedef long long int lli;

const int N = (2e3 + 5);
const int LOG = (20);

int n, q, h[N], l[N], r[N], ar[N][N];

int f(int x, int y) {
	int re = -1;
	for(int i = x; i <= y; i++)
		for(int j = x; j <= y; j++)
			re = max(re, ar[i][j]);
	return re;
}

int main() {
	fast_io();
	// freopen("inp.in", "r", stdin);
	
	memset(ar, -1, sizeof ar);
	cin >> n;
	for(int i = 1; i <= n; i++)
		cin >> h[i] >> l[i] >> r[i];
	cin >> q;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++)
			if(i + l[i] <= j && j <= i + r[i] && j - r[j] <= i && i <= j - l[j])
				ar[i][j] = abs(h[i] - h[j]);
	while(q--) {
		int a, b;
		cin >> a >> b;
		cout << f(a, b) << endl;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...