196192025-12-17 11:19:10szabel26Munkákcpp17Time limit exceeded 0/80689ms9244 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);
        if (a > maxi) maxi = a;
    }

    n = maxi;
    napok.resize(n + 1);
    maxi = 0;

    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
1Accepted1ms316 KiB
2Time limit exceeded685ms2612 KiB
subtask20/10
3Wrong answer2ms316 KiB
4Wrong answer1ms316 KiB
5Wrong answer2ms316 KiB
6Wrong answer2ms316 KiB
7Wrong answer6ms316 KiB
subtask30/10
8Wrong answer1ms316 KiB
9Wrong answer1ms316 KiB
10Partially correct1ms316 KiB
11Accepted1ms380 KiB
12Accepted1ms508 KiB
subtask40/10
13Wrong answer2ms316 KiB
14Wrong answer1ms316 KiB
15Wrong answer2ms316 KiB
16Wrong answer2ms316 KiB
17Wrong answer6ms316 KiB
18Wrong answer1ms316 KiB
19Wrong answer1ms316 KiB
20Wrong answer1ms316 KiB
21Wrong answer6ms316 KiB
22Wrong answer6ms500 KiB
subtask50/10
23Wrong answer1ms316 KiB
24Wrong answer1ms316 KiB
25Partially correct1ms316 KiB
26Accepted1ms380 KiB
27Accepted1ms508 KiB
28Accepted2ms324 KiB
29Accepted2ms564 KiB
30Accepted2ms564 KiB
31Accepted2ms564 KiB
32Accepted2ms564 KiB
subtask60/10
33Wrong answer2ms316 KiB
34Wrong answer1ms316 KiB
35Wrong answer2ms316 KiB
36Wrong answer2ms316 KiB
37Wrong answer6ms316 KiB
38Wrong answer1ms316 KiB
39Wrong answer1ms316 KiB
40Partially correct1ms316 KiB
41Accepted1ms380 KiB
42Accepted1ms508 KiB
43Wrong answer1ms316 KiB
44Wrong answer1ms316 KiB
45Wrong answer1ms316 KiB
46Wrong answer6ms316 KiB
47Wrong answer6ms500 KiB
48Accepted2ms324 KiB
49Accepted2ms564 KiB
50Accepted2ms564 KiB
51Accepted2ms564 KiB
52Accepted2ms564 KiB
53Time limit exceeded688ms564 KiB
54Time limit exceeded689ms564 KiB
55Time limit exceeded688ms564 KiB
56Time limit exceeded689ms756 KiB
57Time limit exceeded686ms564 KiB
subtask70/10
58Wrong answer2ms316 KiB
59Wrong answer1ms316 KiB
60Wrong answer2ms316 KiB
61Wrong answer2ms316 KiB
62Wrong answer6ms316 KiB
63Wrong answer1ms316 KiB
64Wrong answer1ms316 KiB
65Partially correct1ms316 KiB
66Accepted1ms380 KiB
67Accepted1ms508 KiB
68Wrong answer1ms316 KiB
69Wrong answer1ms316 KiB
70Wrong answer1ms316 KiB
71Wrong answer6ms316 KiB
72Wrong answer6ms500 KiB
73Accepted2ms324 KiB
74Accepted2ms564 KiB
75Accepted2ms564 KiB
76Accepted2ms564 KiB
77Accepted2ms564 KiB
78Time limit exceeded688ms564 KiB
79Time limit exceeded689ms564 KiB
80Time limit exceeded688ms564 KiB
81Time limit exceeded689ms756 KiB
82Time limit exceeded686ms564 KiB
83Time limit exceeded683ms4784 KiB
84Time limit exceeded683ms4784 KiB
85Time limit exceeded684ms4872 KiB
86Time limit exceeded683ms4800 KiB
87Time limit exceeded689ms4828 KiB
subtask80/20
88Wrong answer2ms316 KiB
89Wrong answer1ms316 KiB
90Wrong answer2ms316 KiB
91Wrong answer2ms316 KiB
92Wrong answer6ms316 KiB
93Wrong answer1ms316 KiB
94Wrong answer1ms316 KiB
95Partially correct1ms316 KiB
96Accepted1ms380 KiB
97Accepted1ms508 KiB
98Wrong answer1ms316 KiB
99Wrong answer1ms316 KiB
100Wrong answer1ms316 KiB
101Wrong answer6ms316 KiB
102Wrong answer6ms500 KiB
103Accepted2ms324 KiB
104Accepted2ms564 KiB
105Accepted2ms564 KiB
106Accepted2ms564 KiB
107Accepted2ms564 KiB
108Time limit exceeded688ms564 KiB
109Time limit exceeded689ms564 KiB
110Time limit exceeded688ms564 KiB
111Time limit exceeded689ms756 KiB
112Time limit exceeded686ms564 KiB
113Time limit exceeded683ms4784 KiB
114Time limit exceeded683ms4784 KiB
115Time limit exceeded684ms4872 KiB
116Time limit exceeded683ms4800 KiB
117Time limit exceeded689ms4828 KiB
118Time limit exceeded686ms9132 KiB
119Time limit exceeded688ms9032 KiB
120Time limit exceeded686ms9160 KiB
121Time limit exceeded688ms9104 KiB
122Time limit exceeded688ms9208 KiB
123Time limit exceeded688ms9040 KiB
124Time limit exceeded689ms9132 KiB
125Time limit exceeded689ms9136 KiB
126Time limit exceeded683ms9244 KiB
127Time limit exceeded683ms9136 KiB