E Wrapping Chocolate

E - Wrapping Chocolate

Time Limit: 4 sec / Memory Limit: 1024 MB

Score : 500500 points

Problem Statement

Takahashi has NN pieces of chocolate. The ii-th piece has a rectangular shape with a width of A_iAi​ centimeters and a length of B_iBi​ centimeters.
He also has MM boxes. The ii-th box has a rectangular shape with a width of C_iCi​ centimeters and a length of D_iDi​ centimeters.

Determine whether it is possible to put the NN pieces of chocolate in the boxes under the conditions below.

  • A box can contain at most one piece of chocolate.
  • A_i \leq C_jAi​≤Cj​ and B_i \leq D_jBi​≤Dj​ must hold when putting the ii-th piece of chocolate in the jj-th box (they cannot be rotated).

Constraints

  • 1 \leq N \leq M \leq 2\times 10^51≤N≤M≤2×105
  • 1 \leq A_i,B_i,C_i,D_i \leq 10^91≤Ai​,Bi​,Ci​,Di​≤109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN MM
A_1A1​ \ldots… A_NAN​
B_1B1​ \ldots… B_NBN​
C_1C1​ \ldots… C_MCM​
D_1D1​ \ldots… D_MDM​

Output

If it is possible to put the NN pieces of chocolate in the boxes, print Yes; otherwise, print No.


Sample Input 1 Copy

Copy

2 3
2 4
3 2
8 1 5
2 10 5

Sample Output 1 Copy

Copy

Yes

We can put the first piece of chocolate in the third box and the second piece in the first box.


Sample Input 2 Copy

Copy

2 2
1 1
2 2
100 1
100 1

Sample Output 2 Copy

Copy

No

A box can contain at most one piece of chocolate.


Sample Input 3 Copy

Copy

1 1
10
100
100
10

Sample Output 3 Copy

Copy

No

Sample Input 4 Copy

Copy

1 1
10
100
10
100

Sample Output 4 Copy

Copy

Yes

 

#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main()
{
    int n, m;
    cin >> n >> m;
    vector<P> a(n), c(m);
    rep(i, n)cin >> a[i].first;
    rep(i, n)cin >> a[i].second;
    rep(i, m)cin >> c[i].first;
    rep(i, m)cin >> c[i].second;
    sort(a.rbegin(), a.rend());
    sort(c.rbegin(), c.rend());
    multiset<int> s;
    int ind = 0;
    rep(i, n)
    {
        while(ind < m && a[i].first <= c[ind].first)
        {
            s.insert(c[ind].second);
            ind++;
        }
        auto it = s.lower_bound(a[i].second);
        if(it == s.end())
        {
            cout << "No" << endl;
            return 0;
        }
        s.erase(it);
    }
    cout << "Yes" << endl;
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值