Thứ Ba, 3 tháng 5, 2022

THUOCDOAN C++

#include <bits/stdc++.h>
using namespace std;

struct pt
{
    int gt,loai;
};
pt c[200005];
int n;
void nhap()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>c[2*i-1].gt>>c[2*i].gt;
        c[2*i-1].loai=0;
        c[2*i].loai=1;
    }
}
bool ss(pt x, pt y)
{
    if(x.gt<y.gt) return true;
    if(x.gt>y.gt) return false;
    if(x.loai<y.loai) return true;
    if(x.loai>y.loai) return false;
    return false;
}
void giai()
{
    sort(c+1,c+1+2*n,ss);
    int d=0,maxx=0;
    for(int i=1;i<=2*n;i++)
    {
        if(c[i].loai==0) d++;
        else d--;
        if(d>maxx) maxx=d;
    }
    cout<<maxx;
}
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    freopen("thuocdoan.inp","r",stdin);
    freopen("thuocdoan.out","w",stdout);
    nhap();
    giai();
}

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.