Advertisement
STANAANDREY

itec 2021 pb2

Mar 4th, 2023
922
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.86 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. bool solve(vector<int> a, vector<int> p, int b, int e) {
  5.     if (b > e) {
  6.         swap(b, e);
  7.     }
  8.     const int n = a.size();
  9.     vector<pair<int, int>> segs(n);
  10.     for (int i = 0; i < n; i++) {
  11.         segs[i].first = p[i] - a[i];
  12.         segs[i].second = p[i] + a[i];
  13.     }
  14.  
  15.     sort(begin(segs), end(segs));
  16.     int maxEnd = b;
  17.     while (b < e) {
  18.         bool found = false;
  19.         for (const auto &[fi, se] : segs) {
  20.             if (fi > b) {
  21.                 break;
  22.             }
  23.             if (se > b) {
  24.                 maxEnd = max(maxEnd, se);
  25.                 found = true;
  26.             }
  27.         }
  28.         if (!found) {
  29.             return false;
  30.         }
  31.         b = maxEnd;
  32.     }
  33.     return true;
  34. }
  35.  
  36. int main() {
  37.     cerr << solve({1, 3}, {2, 6}, 1, 5) << endl;
  38.     return 0;
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement