196182025-12-17 11:16:14szabel26Munkákcpp17Time limit exceeded 0/80699ms9244 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)
{
    for (auto& e : napok[akt])
    {
        ossz += e.penz;
        sol.push_back(e);
        if (akt != n && akt != n - 1)
        {
            for (int i = akt + 2; i <= n; ++i)
            {
                if (!napok[i].empty()) backtrack(i, ossz);
            }
        }
        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);
    
    /*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
1Accepted2ms316 KiB
2Time limit exceeded686ms2612 KiB
subtask20/10
3Wrong answer1ms316 KiB
4Wrong answer2ms316 KiB
5Wrong answer1ms508 KiB
6Wrong answer2ms316 KiB
7Wrong answer6ms400 KiB
subtask30/10
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Partially correct1ms316 KiB
11Accepted1ms316 KiB
12Accepted1ms316 KiB
subtask40/10
13Wrong answer1ms316 KiB
14Wrong answer2ms316 KiB
15Wrong answer1ms508 KiB
16Wrong answer2ms316 KiB
17Wrong answer6ms400 KiB
18Wrong answer1ms316 KiB
19Wrong answer2ms500 KiB
20Wrong answer1ms316 KiB
21Wrong answer7ms400 KiB
22Wrong answer6ms508 KiB
subtask50/10
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Partially correct1ms316 KiB
26Accepted1ms316 KiB
27Accepted1ms316 KiB
28Accepted2ms500 KiB
29Accepted4ms316 KiB
30Accepted3ms564 KiB
31Accepted3ms564 KiB
32Accepted3ms564 KiB
subtask60/10
33Wrong answer1ms316 KiB
34Wrong answer2ms316 KiB
35Wrong answer1ms508 KiB
36Wrong answer2ms316 KiB
37Wrong answer6ms400 KiB
38Wrong answer1ms316 KiB
39Wrong answer1ms316 KiB
40Partially correct1ms316 KiB
41Accepted1ms316 KiB
42Accepted1ms316 KiB
43Wrong answer1ms316 KiB
44Wrong answer2ms500 KiB
45Wrong answer1ms316 KiB
46Wrong answer7ms400 KiB
47Wrong answer6ms508 KiB
48Accepted2ms500 KiB
49Accepted4ms316 KiB
50Accepted3ms564 KiB
51Accepted3ms564 KiB
52Accepted3ms564 KiB
53Time limit exceeded699ms564 KiB
54Time limit exceeded699ms564 KiB
55Time limit exceeded699ms564 KiB
56Time limit exceeded699ms564 KiB
57Time limit exceeded671ms564 KiB
subtask70/10
58Wrong answer1ms316 KiB
59Wrong answer2ms316 KiB
60Wrong answer1ms508 KiB
61Wrong answer2ms316 KiB
62Wrong answer6ms400 KiB
63Wrong answer1ms316 KiB
64Wrong answer1ms316 KiB
65Partially correct1ms316 KiB
66Accepted1ms316 KiB
67Accepted1ms316 KiB
68Wrong answer1ms316 KiB
69Wrong answer2ms500 KiB
70Wrong answer1ms316 KiB
71Wrong answer7ms400 KiB
72Wrong answer6ms508 KiB
73Accepted2ms500 KiB
74Accepted4ms316 KiB
75Accepted3ms564 KiB
76Accepted3ms564 KiB
77Accepted3ms564 KiB
78Time limit exceeded699ms564 KiB
79Time limit exceeded699ms564 KiB
80Time limit exceeded699ms564 KiB
81Time limit exceeded699ms564 KiB
82Time limit exceeded671ms564 KiB
83Time limit exceeded680ms4784 KiB
84Time limit exceeded680ms4784 KiB
85Time limit exceeded680ms4784 KiB
86Time limit exceeded680ms4784 KiB
87Time limit exceeded680ms4800 KiB
subtask80/20
88Wrong answer1ms316 KiB
89Wrong answer2ms316 KiB
90Wrong answer1ms508 KiB
91Wrong answer2ms316 KiB
92Wrong answer6ms400 KiB
93Wrong answer1ms316 KiB
94Wrong answer1ms316 KiB
95Partially correct1ms316 KiB
96Accepted1ms316 KiB
97Accepted1ms316 KiB
98Wrong answer1ms316 KiB
99Wrong answer2ms500 KiB
100Wrong answer1ms316 KiB
101Wrong answer7ms400 KiB
102Wrong answer6ms508 KiB
103Accepted2ms500 KiB
104Accepted4ms316 KiB
105Accepted3ms564 KiB
106Accepted3ms564 KiB
107Accepted3ms564 KiB
108Time limit exceeded699ms564 KiB
109Time limit exceeded699ms564 KiB
110Time limit exceeded699ms564 KiB
111Time limit exceeded699ms564 KiB
112Time limit exceeded671ms564 KiB
113Time limit exceeded680ms4784 KiB
114Time limit exceeded680ms4784 KiB
115Time limit exceeded680ms4784 KiB
116Time limit exceeded680ms4784 KiB
117Time limit exceeded680ms4800 KiB
118Time limit exceeded686ms9132 KiB
119Time limit exceeded688ms9148 KiB
120Time limit exceeded688ms9132 KiB
121Time limit exceeded688ms9132 KiB
122Time limit exceeded688ms9144 KiB
123Time limit exceeded688ms9132 KiB
124Time limit exceeded689ms9132 KiB
125Time limit exceeded689ms9180 KiB
126Time limit exceeded689ms9244 KiB
127Time limit exceeded689ms9132 KiB