atcoder abc245 - e题解
题意
有 块巧克力和 个盒子,第 块巧克力宽 ,长 ,第 个盒子宽 ,长 。要把所有巧克力放进盒子里,要求 并且 , 如果能把所有巧克力放入盒子中就输出 Yes,否则输出 No。
思路
当看到 和 时,就能想到二维偏序,我们先按第一维排序,这样就只需要关心第二维,只需在选了的盒子中找到一个长 这块巧克力的长的盒子,我们只需要使用找到第一个满足要求的盒子,这个盒子即为最小盒子,在使用双指针求解时需要一个 multiset 维护当前可用盒子的长。
标程
#include<bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
struct Node{
int x, y;
}a[N], b[N];
int n, m, ans;
multiset<int> s;
bool cmp(const Node &i, const Node &j){
return i.x > j.x;
}
int main(){
ios::sync_with_stdio(false), cin.tie(0);
cin >> n >> m;
for(int i = 1; i <= n; i++){
cin >> a[i].x;
}
for(int i = 1; i <= n; i++){
cin >> a[i].y;
}
for(int i = 1; i <= m; i++){
cin >> b[i].x;
}
for(int i = 1; i <= m; i++){
cin >> b[i].y;
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + m + 1, cmp);
for(int i = 1, j = 1; i <= n; i++){
for(; j <= m && b[j].x >= a[i].x; j++){
s.insert(b[j].y);
}
auto it = s.lower_bound(a[i].y);
if(it == s.end()){
cout << "No";
return 0;
}
s.erase(it);
}
cout << "Yes";
return 0;
}