Thứ Tư, 27 tháng 4, 2022

LINE C++

#include <bits/stdc++.h>

using namespace std;

struct dat {
    int a, b;
};
int n, m, s = 0;
bool ok = false;
dat a[100005];
int p[100005];

void nhap(){
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; i++ ) scanf("%d%d", &a[i].a, &a[i].b);
    for (int i = 1; i <= m; i++ ) scanf("%d", &p[i]);
}

bool check1(dat x, dat y){
    if (x.a < y.a) return true;
    else return false;
}

bool check2(int x, int y){
    if (x < y) return true;
    else return false;
}

void xuly(){
    sort(a+1, a+1+n, check1);
    sort(p+1, p+1+m, check2);
    int j = 1;
    p[0] = -1e9;
    p[m+1] = 1e9;
    for (int i = 1; i <= n; i++ ){
        while (a[i].a > p[j]){
            j++;
        }
        if (a[i].a <= p[j] && a[i].b >= p[j]){
            if(a[i].a <= p[j+1] && a[i].b >= p[j+1]){
                s++;
            }
        }
    }
    cout << s << endl;
}

int main(){
    freopen("LINE.INP", "r", stdin);
    freopen("LINE.OUT", "w", stdout);
    nhap();
    xuly();
}

Không có nhận xét nào:

Đăng nhận xét

Lưu ý: Chỉ thành viên của blog này mới được đăng nhận xét.