This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h, w, n;
    ll a, b, c;
    cin >> h >> w >> a >> b >> c >> n;
    vector<int> x(n), y(n);
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> y[i];
    }
    int mx = max(h, w);
    for (int k = 1; k <= max(h, w); ++k) {
        if (c * k > a * k + b) {
            mx = k - 1;
            break;
        }
    }
    auto distance = [&](int i, int j) {
        int f = abs(x[i] - x[j]), s = abs(y[i] - y[j]);
        if (f < s) {
            swap(f, s);
        }
        return s * c + (f <= mx ? f * c : f * a + b);
    };
    cout << distance(0, 1) << '\n';
    return 0;
}
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |