230112026-01-16 10:39:04gyarturMunkákcpp17Runtime error 0/80699ms3320 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

struct Munka{
    int nap;
    int bevetel;
    int index;
};

int n, m;
int utolso;
vector<Munka> munkak;
vector<long long> maxBevetel;
vector<int> munkaIndex;
vector<int> elozoNap;

void Beolvas(){
    cin>>n>>m;
    munkak.resize(m+1);
    maxBevetel.resize(n+1, 0);
    munkaIndex.resize(n+1, 0);
    elozoNap.resize(n+1, 0);
    for(int i = 1; i <= m; i++){
        cin>>munkak[i].nap>>munkak[i].bevetel;
        munkak[i].index = i;
    }
}

bool Comapre(Munka a, Munka b){
    return a.nap < b.nap;
}

int LegnagyobbAznap(int startIndex, int nap){
    int i = startIndex;
    int maxIndex = startIndex;
    while(munkak[i].nap <= nap){
        if(munkak[maxIndex].bevetel < munkak[i].bevetel)maxIndex = i;
        i++;
    }
    return maxIndex;
}

int Elso(){
    if(munkak[1].nap != 1)return 1;
    int indMax = LegnagyobbAznap(1,1);
    maxBevetel[1] = munkak[indMax].bevetel;
    munkaIndex[1] = munkak[indMax].index;
    utolso = 1;
    return indMax;
}

void Feladat(){
    sort(munkak.begin()+1, munkak.end(), Comapre);
    int elozoIndex = Elso();
    for(int i = 2; i <= n && elozoIndex < m; i++){
        int indexMax = LegnagyobbAznap(elozoIndex+1, i);
        if(indexMax){
            munkaIndex[i] = munkak[indexMax].index;
            maxBevetel[i] = munkak[indexMax].bevetel;
            for(int j = 1; j < i-1; j++){
                if(maxBevetel[j] + munkak[indexMax].bevetel > maxBevetel[i]){
                    maxBevetel[i] = maxBevetel[j] + munkak[indexMax].bevetel;
                    elozoNap[i] = j;
                }
            }
            elozoIndex = indexMax;
            if(maxBevetel[i] > maxBevetel[utolso])utolso = i;
        }
    }
}

void Kiir(){
    stack<int> napIndex;
    napIndex.push(utolso);
    cout<<maxBevetel[utolso]<<' ';
    while(elozoNap[napIndex.top()]){
        napIndex.push(elozoNap[napIndex.top()]);
    }
    cout<<napIndex.size()<<'\n';
    while(!napIndex.empty()){
        cout<<munkaIndex[napIndex.top()]<<' ';
        napIndex.pop();
    }
}

int main(){
    Beolvas();
    Feladat();
    Kiir();
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Runtime error138ms1772 KiB
subtask20/10
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Partially correct1ms508 KiB
6Partially correct1ms316 KiB
7Partially correct1ms508 KiB
subtask30/10
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms316 KiB
12Wrong answer1ms316 KiB
subtask40/10
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Partially correct1ms508 KiB
16Partially correct1ms316 KiB
17Partially correct1ms508 KiB
18Wrong answer1ms316 KiB
19Wrong answer1ms316 KiB
20Wrong answer1ms508 KiB
21Accepted1ms316 KiB
22Wrong answer1ms316 KiB
subtask50/10
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Wrong answer1ms316 KiB
26Wrong answer1ms316 KiB
27Wrong answer1ms316 KiB
28Wrong answer1ms316 KiB
29Wrong answer1ms316 KiB
30Wrong answer1ms316 KiB
31Wrong answer1ms316 KiB
32Wrong answer1ms316 KiB
subtask60/10
33Wrong answer1ms316 KiB
34Wrong answer1ms316 KiB
35Partially correct1ms508 KiB
36Partially correct1ms316 KiB
37Partially correct1ms508 KiB
38Wrong answer1ms316 KiB
39Wrong answer1ms316 KiB
40Wrong answer1ms316 KiB
41Wrong answer1ms316 KiB
42Wrong answer1ms316 KiB
43Wrong answer1ms316 KiB
44Wrong answer1ms316 KiB
45Wrong answer1ms508 KiB
46Accepted1ms316 KiB
47Wrong answer1ms316 KiB
48Wrong answer1ms316 KiB
49Wrong answer1ms316 KiB
50Wrong answer1ms316 KiB
51Wrong answer1ms316 KiB
52Wrong answer1ms316 KiB
53Wrong answer1ms316 KiB
54Wrong answer1ms316 KiB
55Wrong answer1ms316 KiB
56Wrong answer1ms316 KiB
57Wrong answer1ms756 KiB
subtask70/10
58Wrong answer1ms316 KiB
59Wrong answer1ms316 KiB
60Partially correct1ms508 KiB
61Partially correct1ms316 KiB
62Partially correct1ms508 KiB
63Wrong answer1ms316 KiB
64Wrong answer1ms316 KiB
65Wrong answer1ms316 KiB
66Wrong answer1ms316 KiB
67Wrong answer1ms316 KiB
68Wrong answer1ms316 KiB
69Wrong answer1ms316 KiB
70Wrong answer1ms508 KiB
71Accepted1ms316 KiB
72Wrong answer1ms316 KiB
73Wrong answer1ms316 KiB
74Wrong answer1ms316 KiB
75Wrong answer1ms316 KiB
76Wrong answer1ms316 KiB
77Wrong answer1ms316 KiB
78Wrong answer1ms316 KiB
79Wrong answer1ms316 KiB
80Wrong answer1ms316 KiB
81Wrong answer1ms316 KiB
82Wrong answer1ms756 KiB
83Time limit exceeded699ms1588 KiB
84Time limit exceeded699ms1604 KiB
85Time limit exceeded699ms1588 KiB
86Time limit exceeded699ms1588 KiB
87Time limit exceeded680ms1588 KiB
subtask80/20
88Wrong answer1ms316 KiB
89Wrong answer1ms316 KiB
90Partially correct1ms508 KiB
91Partially correct1ms316 KiB
92Partially correct1ms508 KiB
93Wrong answer1ms316 KiB
94Wrong answer1ms316 KiB
95Wrong answer1ms316 KiB
96Wrong answer1ms316 KiB
97Wrong answer1ms316 KiB
98Wrong answer1ms316 KiB
99Wrong answer1ms316 KiB
100Wrong answer1ms508 KiB
101Accepted1ms316 KiB
102Wrong answer1ms316 KiB
103Wrong answer1ms316 KiB
104Wrong answer1ms316 KiB
105Wrong answer1ms316 KiB
106Wrong answer1ms316 KiB
107Wrong answer1ms316 KiB
108Wrong answer1ms316 KiB
109Wrong answer1ms316 KiB
110Wrong answer1ms316 KiB
111Wrong answer1ms316 KiB
112Wrong answer1ms756 KiB
113Time limit exceeded699ms1588 KiB
114Time limit exceeded699ms1604 KiB
115Time limit exceeded699ms1588 KiB
116Time limit exceeded699ms1588 KiB
117Time limit exceeded680ms1588 KiB
118Time limit exceeded680ms3124 KiB
119Time limit exceeded680ms3124 KiB
120Time limit exceeded680ms3124 KiB
121Time limit exceeded680ms3124 KiB
122Time limit exceeded683ms3320 KiB
123Time limit exceeded683ms3124 KiB
124Time limit exceeded683ms3316 KiB
125Time limit exceeded683ms3128 KiB
126Time limit exceeded675ms3308 KiB
127Time limit exceeded675ms3124 KiB