#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
using namespace std;
vector<int> a;
int n, en, mn;
int find(int x, int c, int y, int t) {
return t + (c + 1) * abs(x - y);
}
void calc(int x, int l, int r, int c, int t) {
if (t >= mn) return;
if (c == n) {
mn = min(mn, find(x, c, en, t));
return;
}
if (r < l) return;
calc(a[l], l + 1, r, c + 1, find(x, c, a[l], t) + 1);
calc(a[r], l, r - 1, c + 1, find(x, c, a[r], t) + 1);
}
void solve() {
cin >> n;
a = vector<int>(n);
for (auto &i: a) cin >> i;
sort(all(a));
int q; cin >> q;
while (q--) {
int s, t;
cin >> s >> en >> t;
mn = 2e18;
calc(s, 0, n-1, 0, 0);
if (mn <= t)
cout << "Yes\n";
else
cout << "No\n";
}
}
signed main() {
solve();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:33:14: warning: overflow in conversion from 'double' to 'int' changes value from '2.0e+18' to '2147483647' [-Woverflow]
33 | mn = 2e18;
| ^~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |