252742026-02-18 22:25:13abcdÜgyeletcpp17Wrong answer 18/408ms564 KiB
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;

int main(){
    int m,n;cin>>m>>n;
    vector<array<int,3>> v(n);
    for(int i=0;i<n;i++){
        cin>>v[i][0]>>v[i][1];
        v[i][2]=i+1;
    }
    sort(v.begin(),v.end(),[](array<int,3> a,array<int,3> b){
        if(a[0]==b[0])return a[1]>=b[1];
        return a[0]<=b[0];
    });
    int a=1,b=1,i=0;
    vector<int> ans;
    while(a<m+1&&i<n){
        int best=-1;
        int prev=-1;
        while(i<n&&v[i][0]<=a&&prev<b){
            if(best==-1||v[i][1]>v[best][1])best=i;
            prev=v[i][0];
            i++;
        }
        if(best==-1){
            cout<<"0\n";
            return 0;
        }
        a=v[best][1]+1;
        ans.push_back(v[best][2]);
        if(a>b)swap(a,b);
    }
    cout<<ans.size()<<'\n';
    for(int x:ans)cout<<x<<' ';cout<<'\n';
}
SubtaskSumTestVerdictTimeMemory
base18/40
1Accepted0/01ms316 KiB
2Accepted0/04ms316 KiB
3Accepted2/21ms556 KiB
4Accepted2/21ms508 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms500 KiB
8Wrong answer0/21ms316 KiB
9Wrong answer0/21ms396 KiB
10Accepted2/21ms316 KiB
11Wrong answer0/21ms316 KiB
12Accepted1/12ms316 KiB
13Accepted2/23ms316 KiB
14Wrong answer0/23ms508 KiB
15Accepted2/24ms508 KiB
16Accepted3/37ms564 KiB
17Wrong answer0/37ms316 KiB
18Wrong answer0/38ms332 KiB
19Wrong answer0/38ms536 KiB
20Wrong answer0/38ms516 KiB