题解:
#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;
}
本站资源均来自互联网,仅供研究学习,禁止违法使用和商用,产生法律纠纷本站概不负责!如果侵犯了您的权益请与我们联系!
转载请注明出处: 免费源码网-免费的源码资源网站 » D. Searchlights
发表评论 取消回复