题目

题解:

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define lson p << 1
#define rson p << 1 | 1
#define ll long long
#define pii pair<int, int>
#define ld long double
const int maxn = 1e6 + 5, inf = 1e9, maxm = 4e4 + 5, base = 337;
const int N = 1e6;
const int mod = 1e9 + 7;
// const int mod = 998244353;
// const __int128 mod = 212370440130137957LL;
int n, m;
int a[maxn], b[maxn];

void solve(){
    ll res = 0;
    int k, q, r;
    cin >> n >> m;
    // vector<int> a(n + 1);
    // for(int i = 1; i <= n; i++){
    //     cin >> a[i];
    // }
    vector<pii> a(n + 1), b(m + 1);
    for(int i = 1; i <= n; i++){
        cin >> a[i].first >> a[i].second;
    }
    for(int i = 1; i <= m; i++){
        cin >> b[i].first >> b[i].second;
    }
    vector<int> f(maxn, 0);
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= m; j++){
            int dx = b[j].first - a[i].first;
            int dy = b[j].second - a[i].second;
            if(dx < 0) continue;
            f[dx] = max(f[dx], dy + 1);
        }
    }
    for(int i = N; i >= 0; i--){
        f[i] = max(f[i + 1], f[i]);
    }
    res = inf;
    for(int x = 0; x <= N + 1; x++){
        res = min(res, x + f[x]);
    }
    cout << res << '\n';
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout << fixed << setprecision(9);

    int T = 1;
    // cin >> T;
    while (T--){
        solve();
    }
    return 0;
}

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部