Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cmath>
- #include <cstdlib>
- using namespace std;
- int min_element(int *nums){
- if (nums[0] > nums[1]) return nums[0];
- return nums[1];
- }
- int main(){
- long long int start;
- long long int olymp;
- long long int portals_qnt;
- cin>>start;
- cin>>olymp;
- cin>>portals_qnt;
- long long int lp_from_start = -pow(10, 8);
- long long int rp_from_start = pow(10, 8);
- long long int lp_from_olymp = -pow(10, 8);
- long long int rp_from_olymp = pow(10, 8);
- for (int i = 0; i < portals_qnt; i++){
- int portal_coord;
- cin>>portal_coord;
- if (portal_coord < olymp and portal_coord > lp_from_olymp) lp_from_olymp = portal_coord;
- else if (portal_coord >= olymp and portal_coord < rp_from_olymp) rp_from_olymp = portal_coord;
- if (portal_coord < start and portal_coord > lp_from_start) lp_from_start = portal_coord;
- else if (portal_coord >= start and portal_coord < rp_from_start) rp_from_start = portal_coord;
- }
- long long int &time_to_olymp_from_portal = *min_element({abs(rp_from_olymp - olymp), abs(olymp - lp_from_olymp)});
- long long int &time_to_start_from_portal = *min_element({abs(rp_from_start - start), abs(start - lp_from_start)});
- long long int time_through_portal = time_to_olymp_from_portal + time_to_start_from_portal + 1;
- long long int time_to_olymp_from_start = abs(start - olymp);
- long long int &res = *min_element({time_through_portal, time_to_olymp_from_start});
- cout<<res;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement