제출 #895497

#제출 시각아이디문제언어결과실행 시간메모리
895497kh0iTwo Antennas (JOI19_antennas)C++17
13 / 100
50 ms22612 KiB
#include "bits/stdc++.h" using namespace std; using ll = long long; const int N = 2e5 + 3; int n, q; int h[N], a[N], b[N], l[N], r[N]; namespace Sub12{ bool valid_input(){ return n <= 2000; } int f[2003][2003]; int calc(int i, int j){ int d = abs(j - i); if(d < a[i] or d > b[i] or d < a[j] or d > b[j]) return -1; return abs(h[i] - h[j]); } void solve(){ for(int i = 1; i <= n; ++i) f[i][i] = -1; for(int len = 2; len <= n; ++len) for(int l = 1, r = len; r <= n; ++l, ++r) f[l][r] = max(max(f[l + 1][r], f[l][r - 1]), calc(l, r)); for(int i = 1; i <= q; ++i) cout << f[l[i]][r[i]] << '\n'; } } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); cin >> n; for(int i = 1; i <= n; ++i) cin >> h[i] >> a[i] >> b[i]; cin >> q; for(int i = 1; i <= q; ++i) cin >> l[i] >> r[i]; if(Sub12::valid_input()) Sub12::solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...