Thứ Ba, 3 tháng 5, 2022

COVER C++

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

int n, a, b;
struct line{
    int x,y,pos;
};
line d[100001];

void nhap()
{
    //cin>>n>>a>>b;
    scanf("%d%d%d",&n,&a,&b);
    for (int i=1;i<=n;i++)
    {
        //cin>>d[i].x>>d[i].y;
        scanf("%d%d",&d[i].x,&d[i].y);
        d[i].pos = i;
    }
}

bool cmp(line &t1, line &t2){
    if(t1.y<t2.y) return true;
    if(t1.y>t2.y) return false;
    if(t1.x>t2.x) return true;
    if(t1.x<t2.x) return false;
    return false;
}

vector <int> res;

void xuat()
{
    cout<<res.size()<<endl;
    for (int i=0;i<res.size();i++){
        cout<<res[i]<<endl;
    }
}

void giai()
{
    int v,k;
    sort(d+1, d+1+n, cmp);
    v=a;
    k=1;
    bool ok=false,co;
    while(v<b||ok==false)
    {
        ok=true;
        co=false;
        for(int j=n;j>=k;j--)
        {
            //cout<<d[j].x<<" "<<v<<" "<<k<<" "<<b<<endl;
            if(d[j].x<=v)
            {
                res.push_back(d[j].pos);
                v=d[j].y;
                k=j+1;
                co=true;
                break;
            }
        }
        if(co==false)
        {
            cout<<"-1";
            return;
        }
    }
    xuat();
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    freopen("COVER.inp", "r", stdin);
    freopen("COVER.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.