#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e3 + 100;
int dp[maxn][maxn];
int l[maxn], r[maxn], h[maxn];
bool in(int i, int j)
{
int d = abs(i - j);
return (d >= l[j] and d <= r[j]);
}
int c(int i, int j)
{
if (in(i, j) and in(j, i))
{
return abs(h[i] - h[j]);
}
return -1;
}
int main()
{
int n;
cin >> n;
for (int i = 1;i <= n;i++)
{
cin >> h[i] >> l[i] >> r[i];
}
for (int i = 1;i <= n;i++)
{
for (int j = 1;j <= n;j++)
{
dp[i][j] = -1;
}
}
for (int d = 1;d < n;d++)
{
for (int i = 1;i <= n - d;i++)
{
int j = i + d;
dp[i][j] = max(c(i, j), max(dp[i + 1][j], dp[i][j - 1]));
}
}
int q;
cin >> q;
while (q--)
{
int l, r;
cin >> l >> r;
cout << dp[l][r] << '\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... |