Language: C++

#include <algorithm>
#include <cstring>
#include <ctime>
#include <iostream>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

#ifdef __APPLE__
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...)
#endif

const int N = (int)1e6 + 123;
const int MOD = (int)1e9 + 7;
const int inf = (int)5e8;
const long long infll = (long long)1e17;


const double GOOD_PATH_LEN = 20 - 5 * acos(-1.0);
const double BAD_PATH_LEN = 10 * acos(-1.0) - 10;

int x[N];
int y[N];

bool inside(int x1, int y1, int x2, int y2, int x3, int y3) {
    int min_y = min(y1, y2);
    int max_y = max(y1, y2);
    return x1 <= x3 && x3 <= x2 && min_y <= y3 && y3 <= max_y;
}


pair<int, int> max_value(pair<int, int> lhs, pair<int, int> rhs) {
    if (lhs.first != rhs.first) {
        if (lhs.first < rhs.first) {
            return rhs;
        }
        return lhs;
    }
    if (lhs.second < rhs.second) {
        return lhs;
    }
    return rhs;
}

void solve() {
    int x1, y1, x2, y2;
    int n;
    scanf("%d %d %d %d", &x1, &y1, &x2, &y2);
    if (x1 > x2) {
        swap(x1, x2);
        swap(y1, y2);
    }
    long long path = abs(x1 - x2) + abs(y1 - y2);
    path *= 100ll;
    scanf("%d", &n);
    vector<pair<int, int>> usefull;
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &x[i], &y[i]);
        if (inside(x1, y1, x2, y2, x[i], y[i])) {
            usefull.push_back({x[i], y[i]});
        }
    }
    sort(usefull.begin(), usefull.end());
    if (x1 == x2 || y1 == y2) {
        printf("%.10lf\n", path + BAD_PATH_LEN * usefull.size());
        return;
    }
    int max_fountains = 0;
    vector<pair<int, int>> dp(usefull.size() + 1);
    for (int i = 1; i <= usefull.size(); ++i) {
        auto cur_fountain = usefull[i - 1];
        for (int j = 0; j < i; ++j) {
            if (dp[j].second < cur_fountain.second) {
                dp[i] = max_value(dp[i], {dp[j].first + 1, cur_fountain.second});
            }
        }
    }
    max_fountains = dp[usefull.size()].first;
    sort(usefull.begin(), usefull.end(), [](const pair<int, int> a, const pair<int, int> b) {
        if (a.second != b.second) {
            return a.second < b.second;
        }
        return a.first < b.first;
    });
    dp.clear();
    dp.resize(usefull.size() + 1);
    for (int i = 1; i <= usefull.size(); ++i) {
        auto cur_fountain = usefull[i];
        for (int j = 0; j < i; ++j) {
            if (dp[j].second < cur_fountain.first) {
                dp[i] = max_value(dp[i], {dp[j].first + 1, cur_fountain.first});
            }
        }
    }
    max_fountains = max(max_fountains, dp[usefull.size()].first);
    printf("%.10lf", path - max_fountains * GOOD_PATH_LEN);
}

int main() {
#ifdef __APPLE__
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    while (t--) {
        solve();
    }
    return 0;
}

Compiler output:
a.cc:26:39: error: 'acos' was not declared in this scope
   26 | const double GOOD_PATH_LEN = 20 - 5 * acos(-1.0);
      |                                       ^~~~
a.cc:27:34: error: 'acos' was not declared in this scope
   27 | const double BAD_PATH_LEN = 10 * acos(-1.0) - 10;
      |                                  ^~~~