196172025-12-17 11:09:03szabel26Munkákcpp17Time limit exceeded 0/80690ms9800 KiB
// munkak.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct adat {
    int sorszam, penz;
};

vector<vector<adat>>napok;
vector<adat>sol;
vector<adat>sol2;

int n, m, maxi = 0;

int hasonlit(adat a, adat b)
{
    return a.penz < b.penz;
}

void check(int ossz)
{
    if (ossz >= maxi)
    {
        maxi = ossz;
        sol2 = sol;
        //sol.clear();
    }
}

void backtrack(int akt, int ossz, int lep)
{
    for (auto& e : napok[akt])
    {
        ossz += e.penz;
        sol.push_back(e);
        for (int i = akt + 2; i <= n; ++i)
        {
            if(!napok[i].empty()) backtrack(i, ossz, lep + 1);
        }
        check(ossz);
        if(!sol.empty()) sol.pop_back();
    }
}

int main()
{
    cin >> n >> m;
    napok.resize(n + 1);

    int a;
    adat b;
    for (int i = 1; i <= m; ++i)
    {
        cin >> a >> b.penz;
        b.sorszam = i;
        napok[a].push_back(b);
        //napok[a + 1].push_back(b);
    }

    for (int i = 1; i <= n; ++i) if(!napok[i].empty()) backtrack(i, 0, 1);
    
    /*for (int i = 1; i <= m; ++i)
    {
        sort(napok[i].begin(), napok[i].end(), hasonlit);
    }*/

    cout << maxi << " " << sol2.size() << endl;
    for (auto& e : sol2)
    {
        cout << e.sorszam << " ";
    }
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Time limit exceeded679ms2612 KiB
subtask20/10
3Wrong answer1ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer1ms316 KiB
6Wrong answer2ms316 KiB
7Wrong answer6ms316 KiB
subtask30/10
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Partially correct1ms316 KiB
11Accepted1ms392 KiB
12Accepted1ms316 KiB
subtask40/10
13Wrong answer1ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer1ms316 KiB
16Wrong answer2ms316 KiB
17Wrong answer6ms316 KiB
18Wrong answer1ms500 KiB
19Wrong answer1ms508 KiB
20Wrong answer1ms316 KiB
21Wrong answer7ms316 KiB
22Wrong answer6ms400 KiB
subtask50/10
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Partially correct1ms316 KiB
26Accepted1ms392 KiB
27Accepted1ms316 KiB
28Accepted1ms512 KiB
29Accepted4ms564 KiB
30Accepted3ms564 KiB
31Accepted3ms760 KiB
32Accepted3ms568 KiB
subtask60/10
33Wrong answer1ms316 KiB
34Wrong answer1ms316 KiB
35Wrong answer1ms316 KiB
36Wrong answer2ms316 KiB
37Wrong answer6ms316 KiB
38Wrong answer1ms316 KiB
39Wrong answer1ms316 KiB
40Partially correct1ms316 KiB
41Accepted1ms392 KiB
42Accepted1ms316 KiB
43Wrong answer1ms500 KiB
44Wrong answer1ms508 KiB
45Wrong answer1ms316 KiB
46Wrong answer7ms316 KiB
47Wrong answer6ms400 KiB
48Accepted1ms512 KiB
49Accepted4ms564 KiB
50Accepted3ms564 KiB
51Accepted3ms760 KiB
52Accepted3ms568 KiB
53Time limit exceeded680ms564 KiB
54Time limit exceeded680ms564 KiB
55Time limit exceeded680ms756 KiB
56Time limit exceeded681ms564 KiB
57Time limit exceeded675ms756 KiB
subtask70/10
58Wrong answer1ms316 KiB
59Wrong answer1ms316 KiB
60Wrong answer1ms316 KiB
61Wrong answer2ms316 KiB
62Wrong answer6ms316 KiB
63Wrong answer1ms316 KiB
64Wrong answer1ms316 KiB
65Partially correct1ms316 KiB
66Accepted1ms392 KiB
67Accepted1ms316 KiB
68Wrong answer1ms500 KiB
69Wrong answer1ms508 KiB
70Wrong answer1ms316 KiB
71Wrong answer7ms316 KiB
72Wrong answer6ms400 KiB
73Accepted1ms512 KiB
74Accepted4ms564 KiB
75Accepted3ms564 KiB
76Accepted3ms760 KiB
77Accepted3ms568 KiB
78Time limit exceeded680ms564 KiB
79Time limit exceeded680ms564 KiB
80Time limit exceeded680ms756 KiB
81Time limit exceeded681ms564 KiB
82Time limit exceeded675ms756 KiB
83Time limit exceeded680ms4784 KiB
84Time limit exceeded680ms4900 KiB
85Time limit exceeded680ms4720 KiB
86Time limit exceeded680ms4784 KiB
87Time limit exceeded677ms4784 KiB
subtask80/20
88Wrong answer1ms316 KiB
89Wrong answer1ms316 KiB
90Wrong answer1ms316 KiB
91Wrong answer2ms316 KiB
92Wrong answer6ms316 KiB
93Wrong answer1ms316 KiB
94Wrong answer1ms316 KiB
95Partially correct1ms316 KiB
96Accepted1ms392 KiB
97Accepted1ms316 KiB
98Wrong answer1ms500 KiB
99Wrong answer1ms508 KiB
100Wrong answer1ms316 KiB
101Wrong answer7ms316 KiB
102Wrong answer6ms400 KiB
103Accepted1ms512 KiB
104Accepted4ms564 KiB
105Accepted3ms564 KiB
106Accepted3ms760 KiB
107Accepted3ms568 KiB
108Time limit exceeded680ms564 KiB
109Time limit exceeded680ms564 KiB
110Time limit exceeded680ms756 KiB
111Time limit exceeded681ms564 KiB
112Time limit exceeded675ms756 KiB
113Time limit exceeded680ms4784 KiB
114Time limit exceeded680ms4900 KiB
115Time limit exceeded680ms4720 KiB
116Time limit exceeded680ms4784 KiB
117Time limit exceeded677ms4784 KiB
118Time limit exceeded689ms9136 KiB
119Time limit exceeded690ms9228 KiB
120Time limit exceeded689ms9228 KiB
121Time limit exceeded690ms9168 KiB
122Time limit exceeded685ms9044 KiB
123Time limit exceeded686ms9132 KiB
124Time limit exceeded685ms9140 KiB
125Time limit exceeded686ms9132 KiB
126Time limit exceeded666ms9020 KiB
127Time limit exceeded667ms9800 KiB