32972023-02-24 15:04:42zsomborÜgyeletcpp17Accepted 40/4010ms4508 KiB
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

struct ugy {
    int ind, l, r;
    ugy() {
        ind = l = r = 0;
    }
};

int m, n, nxt = 1, nxt2 = 1, mxi = 0, mxi2 = 0, i = 1;
vector <ugy> v;
vector <int> ans;

bool R(ugy a, ugy b) {
    return (a.l < b.l ? true : false);
}

void get_mxi() {
    if (v[i].r > v[mxi2].r) mxi2 = i;
    if (v[mxi].r < v[mxi2].r) swap(mxi, mxi2);
}

int main()
{
    cin >> m >> n;
    v.resize(n + 2, ugy());
    for (int i = 1; i <= n; i++) {
        v[i].ind = i;
        cin >> v[i].l >> v[i].r;
    }
    v[n + 1].l = v[n + 1].r = 1e9;
    sort(v.begin(), v.end(), R);
    while (nxt <= m) {
        for (; v[i].l <= nxt; i++) get_mxi();
        if (v[mxi].r < nxt) { cout << 0; return 0; }
        ans.push_back(v[mxi].ind); nxt = v[mxi].r + 1;
        if (nxt > nxt2) swap(nxt, nxt2);
        mxi = mxi2; mxi2 = 0;
    }
    cout << ans.size() << endl;
    for (int a : ans) cout << a << " ";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1876 KiB
2Accepted0/06ms2304 KiB
3Accepted2/23ms2332 KiB
4Accepted2/23ms2572 KiB
5Accepted2/23ms2716 KiB
6Accepted2/23ms2828 KiB
7Accepted2/23ms2960 KiB
8Accepted2/23ms3076 KiB
9Accepted2/23ms3252 KiB
10Accepted2/23ms3464 KiB
11Accepted2/23ms3544 KiB
12Accepted1/14ms3684 KiB
13Accepted2/24ms3772 KiB
14Accepted2/24ms3784 KiB
15Accepted2/26ms3792 KiB
16Accepted3/310ms4052 KiB
17Accepted3/38ms4124 KiB
18Accepted3/310ms4272 KiB
19Accepted3/310ms4232 KiB
20Accepted3/310ms4508 KiB