Submission #993453

#TimeUsernameProblemLanguageResultExecution timeMemory
993453vladiliusTwo Antennas (JOI19_antennas)C++17
2 / 100
3085 ms6400 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second #define ins insert int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin>>n; vector<int> h(n + 1), a(n + 1), b(n + 1); for (int i = 1; i <= n; i++){ cin>>h[i]>>a[i]>>b[i]; } auto check = [&](int& i, int& k){ return (a[i] <= k && k <= b[i]); }; int q; cin>>q; while (q--){ int l, r, out = -1; cin>>l>>r; for (int i = l; i <= r; i++){ for (int j = i + 1; j <= r; j++){ int dif = j - i; if (check(i, dif) && check(j, dif)){ out = max(out, abs(h[i] - h[j])); } } } cout<<((out == -1) ? -1: out)<<"\n"; } // (i -> j): a[i] <= abs(i - j) <= b[i] // (j -> i): a[j] <= abs(j - i) <= b[j] // i <-> j: abs(i - j) є [a[i], b[i]], [a[j], b[j]] }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...