链接:https://vjudge.net/contest/399982#problem/D
思路:
其实就是个枚举,想明白的话就很简单,想不明白就会绕进去。
题目其实很简单,就是考虑怎么通过向右向上走能出去,且走的次数最小。参考题解的枚举方式:在有效的监控中枚举,考虑横坐标差为x的监控向上走y步能够逃离。然后再来枚举向右走1e6-0步,能走出去的向上+向右走的最小值为多少。
向右走的步数从大到小枚举过程中,比如向右走了x步,那么小于x的都会通过向右移动来出去,而大于x的则还需要结合向上才能移出去,用mx来维护后面向上移动的最大值即可。

代码:

#include<bits/stdc++.h>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i] >> b[i];
    }
    vector<int> c(m), d(m);
    for(int i = 0; i < m; i++) {
        cin >> c[i] >> d[i];
    }
    const int MAX = 1000010;
    vector<int> v(MAX);
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++) {
            if(a[i] <= c[j]) {
                v[c[j] - a[i]] = max(v[c[j] - a[i]], d[j] - b[i] + 1);
            }
        }
    }
    int ans = 2 * MAX;
    int mx = 0;
    for(int dx = MAX - 1; dx >= 0; dx--) {
        mx = max(mx, v[dx]);
        ans = min(ans, dx + mx);
    }
    cout << ans << '\n';
    return 0; 
}