Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- bool solve(vector<int> a, vector<int> p, int b, int e) {
- if (b > e) {
- swap(b, e);
- }
- const int n = a.size();
- vector<pair<int, int>> segs(n);
- for (int i = 0; i < n; i++) {
- segs[i].first = p[i] - a[i];
- segs[i].second = p[i] + a[i];
- }
- sort(begin(segs), end(segs));
- int maxEnd = b;
- while (b < e) {
- bool found = false;
- for (const auto &[fi, se] : segs) {
- if (fi > b) {
- break;
- }
- if (se > b) {
- maxEnd = max(maxEnd, se);
- found = true;
- }
- }
- if (!found) {
- return false;
- }
- b = maxEnd;
- }
- return true;
- }
- int main() {
- cerr << solve({1, 3}, {2, 6}, 1, 5) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement