253422026-02-19 11:50:23abcdÜgyeletcpp17Wrong answer 35/408ms560 KiB
#include <bits/stdc++.h>
using namespace std;

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,second=-1;
    vector<int> ans;
    while(a<m+1&&i<n){
        int best=-1;
        bool yes=false;
        if(second!=-1){
            best=second;
            yes=true;
            second=-1;
        }
        while(i<n&&v[i][0]<=a){
            if(best==-1||v[i][1]>v[best][1]){
                second=best;
                best=i;
            }
            if(yes&&best!=i){
                if(second==-1||v[i][1]>v[second][1])second=i;
            }
            i++;
            yes=true;
        }
        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
base35/40
1Accepted0/01ms316 KiB
2Accepted0/04ms316 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Accepted2/21ms316 KiB
6Accepted2/21ms316 KiB
7Wrong answer0/21ms552 KiB
8Accepted2/21ms316 KiB
9Accepted2/22ms500 KiB
10Accepted2/22ms316 KiB
11Accepted2/21ms508 KiB
12Accepted1/12ms560 KiB
13Accepted2/22ms316 KiB
14Accepted2/23ms316 KiB
15Accepted2/24ms316 KiB
16Accepted3/37ms516 KiB
17Wrong answer0/37ms316 KiB
18Accepted3/38ms512 KiB
19Accepted3/38ms516 KiB
20Accepted3/38ms512 KiB