Problem Author: | Andriy Kholod (Connect) |
Prepared by: | Andriy Kholod (Connect) |
Analysis: | Andriy Kholod (Connect) |
Solution
Consider two cases. The first case is when we visit the first office first and the second office second. The second case is when we visit the second office first and the first office second. Then we only need to check if we can complete our tasks in each office in each of these two cases.
The asymptotic complexity of the solution is O(1).
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define endl '\n'
#define yes cout<<"1"<<endl
#define no cout<<"0"<<endl
void solve() {
ll r1 , r2 , r3;
cin>>r1>>r2>>r3;
ll q1 , q2 , t1;
cin>>q1>>q2>>t1;
ll w1 , w2 , t2;
cin>>w1>>w2>>t2;
bool ok = 0;
// first office will be first
ll road = min(r1 , r2+r3);
if (max(road , q1) + t1 <= q2 && max(max(road , q1) + t1 + min(r3 , r1+r2) , w1) + t2 <= w2 ) ok = 1;
// second office will be first
road = min(r2 , r1+r3);
if (max(road , w1) + t2 <= w2 && max(max(road , w1) + t2 + min(r3 , r1+r2) , q1) + t1 <= q2 ) ok = 1;
if (ok) yes;
else no;
}
signed main() {
speed;
int test;
test=1;
cin>>test;
for (int tt=1 ;tt<=test ; tt++) {
solve();
}
return 0;
}