E - Wrapping Chocolate -- AC Beginner 245


 1 #include
 2 
 3 typedef long long ll;
 4 
 5 const int N = 4e5+10,M = N * 4,INF = 0x3f3f3f3f,mod = 1e9+7;
 6 struct Node{
 7     int x,y;
 8     bool box;
 9     bool operator<(const Node &a)const
10     {
11         if(a.x == x)return a.box < box;
12         return a.x < x;
13     }
14 }a[N];
15 std::multiset<int> st;
16 
17 int main()
18 {
19     std::ios::sync_with_stdio(false);
20     std::cin.tie(nullptr);
21     std::cout.tie(nullptr);
22     int n,m;
23     std::cin>>n>>m;
24     for(int i = 1 ; i <= n ; i++)
25     {
26         int x;
27         std::cin>>x;
28         a[i].x = x;
29     }
30     for(int i = 1 ; i <= n ; i++)
31     {
32         int x;
33         std::cin>>x;
34         a[i].y = x;
35         a[i].box = false;
36     }
37     for(int i = n + 1 ; i <= m + n; i++)
38     {
39         int x;
40         std::cin>>x;
41         a[i].x = x;
42     }
43     for(int i = n + 1 ; i <= m + n ; i++)
44     {
45         int x;
46         std::cin>>x;
47         a[i].y = x;
48         a[i].box = true;
49     }
50     std::sort(a+1,a+1+n+m);
51     for(int i = 1 ; i <= n + m; i++)
52     {
53         if(a[i].box)
54         {
55             st.insert(a[i].y);
56         }
57         else
58         {
59             auto it = st.lower_bound(a[i].y);
60             if(it!=st.end())st.erase(it);
61             else
62             {
63                 std::cout<<"No";
64                 return 0;
65             }
66         }
67     }
68     std::cout<<"Yes";
69     return 0;
70 }