124372024-12-17 19:57:47szabelrMekk Mester munkái (50 pont)cpp17Accepted 50/5092ms2956 KiB
#include <iostream>
#include <algorithm>
using namespace std;

struct munka {
    int kn, vn, sz;
};

int h(munka x, munka y) {
    if (x.vn < y.vn)
        return true;
    else if (x.vn > y.vn)
        return false;
    else
        return x.kn > y.kn;
}

int s1[100001] = { 0 };
int s2[100001] = { 0 };
int jok1 = 0, jok2 = 0;

int jokt1[100001] = { 0 };
int jokt2[100001] = { 0 };

int a = 0, b = 0;
munka t[100001];

int main() {
    int n, H;
    cin >> n >> H;
    int veg1=0, veg2=0;
    for (int i = 0; i < n; i++) {
        cin >> t[i].kn >> t[i].vn;
        t[i].sz = i + 1; 
    }

    sort(t, t + n, h); 

    for (int i = 0; i < n; i++) {
        int lehet1 = 1;
        for (int j = t[i].kn; j <= t[i].vn; j++) {
            if (s1[j] == 1) {
                lehet1 = 0;
                break;
            }
        }
        int lehet2 = 1;
        for (int j = t[i].kn; j <= t[i].vn; j++) {
            if (s2[j] == 1) {
                lehet2 = 0;
                break;
            }
        }
        if (lehet1 and lehet2==0) {
            for (int j = t[i].kn; j <= t[i].vn; j++) {
                s1[j] = 1;
            }
            veg1 = t[i].vn;
            jok1++;
            jokt1[a++] = t[i].sz;
        }
        else if (lehet2 and lehet1==0) {
             for (int j = t[i].kn; j <= t[i].vn; j++) {
                   s2[j] = 1;
             }
             veg2 = t[i].vn;
             jok2++;
             jokt2[b++] = t[i].sz;
        }
        else if (lehet1 and lehet2) {
            if (veg1 > veg2) {
                for (int j = t[i].kn; j <= t[i].vn; j++) {
                    s1[j] = 1;
                }
                veg1 = t[i].vn;
                jok1++;
                jokt1[a++] = t[i].sz;
            }
            else {
                for (int j = t[i].kn; j <= t[i].vn; j++) {
                    s2[j] = 1;
                }
                veg2 = t[i].vn;
                jok2++;
                jokt2[b++] = t[i].sz;
            }
        }
    }

    cout << jok1 << " " << jok2 << endl;

    for (int i = 0; i < jok1; i++) {
        cout << jokt1[i] << " ";
    }
    cout << endl;

    for (int i = 0; i < jok2; i++) {
        cout << jokt2[i] << " ";
    }
    cout << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/01ms500 KiB
2Accepted0/08ms568 KiB
3Accepted1/12ms780 KiB
4Accepted1/12ms824 KiB
5Accepted2/22ms824 KiB
6Accepted2/22ms824 KiB
7Accepted2/22ms824 KiB
8Accepted2/22ms1080 KiB
9Accepted3/31ms320 KiB
10Accepted1/14ms1080 KiB
11Accepted1/13ms1080 KiB
12Accepted2/23ms932 KiB
13Accepted2/23ms1172 KiB
14Accepted2/23ms1080 KiB
15Accepted2/23ms988 KiB
16Accepted3/32ms320 KiB
17Accepted2/290ms2360 KiB
18Accepted2/292ms2296 KiB
19Accepted4/487ms2348 KiB
20Accepted4/483ms2232 KiB
21Accepted4/485ms2360 KiB
22Accepted4/485ms2368 KiB
23Accepted4/490ms2956 KiB