232422026-01-16 19:03:00AkosVagyokMunkákcpp17Partially correct 0/80699ms2372 KiB
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>
using namespace std;
ifstream fin("be.in");
struct munka {
    int nap;
    int x;
    int y;
    int index;
};
bool comp2(munka a, munka b) {
    return a.x < b.x;
}
bool comp(munka a, munka b) {
    return a.nap < b.nap;
}
vector <munka> sdt;
vector <munka> t;
int n, m;
void be() {
    cin >> m >> n;
    t.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        int a, b;
        cin >> a >> b;
        t[i].nap = a;
        t[i].x = b;
        t[i].y = a + 1;
        t[i].index = i;
    }
    sort(t.begin(), t.end(), comp);
}
void ki() {
    cout << endl << endl << endl << endl << endl;
    for (int i = 1; i <= n; i++) {
        cout << t[i].nap << ' ' << t[i].x << endl;
    }
    cout << endl << endl << endl << endl << endl;
}
struct munkaba {
    int os;
    int hossz;
};
bool compare(munkaba a, munkaba b) {
    return a.hossz < b.hossz;

}
stack <munkaba> st;
vector <int> seg2;
vector <munkaba> seg;
vector <int> os;
vector <int> hossz;
void munka() {
    hossz.resize(n + 1);
    os.resize(n + 1);
    for (int i = 1; i <= n; i++) {
        hossz[i] = t[i].x;
        //cout << hossz[i] << ' '<<endl;
    }
    for (int i = 1; i <= n; i++) {
        int maxx = 0;
        int index1= 0;
        if (i>=3&&t[i-1].nap!=t[i-2].nap&& t[i-1].nap < t[i].nap) {  
            for (int j = i - 1; j >= 1 && j >= i - 2; j--) {
                //cout << j << ' ';   
                if (t[j].y != t[i].nap && t[j].nap != t[i].nap) {
                    if (hossz[j] + hossz[i] > maxx) {
                        munkaba  a;
                        a.hossz = hossz[i] + hossz[j];
                        maxx = a.hossz;
                        index1 = j;
                        a.os = j;
                        seg.push_back(a);
                    }
                }
                else {
                    if (t[os[j]].y != t[i].nap && t[os[j]].nap != t[i].nap) {
                        if (hossz[os[j]] + hossz[i] > maxx) {
                            munkaba  a;
                            a.hossz = hossz[i] + hossz[os[j]];
                            a.os = os[j];
                            maxx = a.hossz;
                            index1 = os[j];
                            seg.push_back(a);
                        }
                    }
                }
                
            }
        }
        else {
            for (int j = i - 1; j >= 1; j--) {
                if (maxx < hossz[j]+hossz[i]) {
                    if (t[j].y != t[i].nap && t[j].nap != t[i].nap) {
                        munkaba  a;
                        index1 = j;
                        a.hossz = hossz[i] + hossz[j];
                        maxx = a.hossz;
                        a.os = j;
                        seg.push_back(a);
                    }
                }
            }
        }
        if (maxx) {
            os[i] = index1;
            hossz[i] = maxx;
        }
    }

}
int k = 1;
void visszalepesszamolas(int kcs) {
    if (os[kcs]) {
        k++;
        visszalepesszamolas(os[kcs]);
    }
}
void visszalepes(int kcs) {
    if (os[kcs]) {
        cout << t[os[kcs]].index << ' ';
        visszalepes(os[kcs]);
    }
}
int db6 = 0;
void munka2() {
    sort(t.begin(), t.end(), comp2);
    sdt.push_back(t.back());
    /*for (int i = 1; i <= n; i++) {
        cout << t[i].x << ' ' << t[i].index<<endl;
    }*/
    /*cout << endl;*/
    db6 += t.back().x;
    for (int i = t.size() - 2; i >= 1; i--) {
        bool d=1;
        for (int j = 0; j < sdt.size(); j++) {
            if (!(t[sdt[j].index].nap!=t[i].nap&&t[sdt[j].index].nap!=t[i].y&& t[sdt[j].index].y != t[i].nap)) {
                d = false;
            }
        }
        if (d) {
            sdt.push_back(t[i]);
            db6 += t[i].x;
        }
    }

}
int main()
{
    be();
    //ki();
    //munka();
    //cout << endl << endl << endl;
    //int maxx = hossz[1];
    //int index = 1;
    ///*for (int i = 1; i <= n; i++) {
    //    cout << hossz[i] << ' ';
    //}*/
    //cout << endl;
    //for (int i = 1; i <= n; i++) {
    //    if (maxx < hossz[i]) {
    //        maxx = hossz[i];
    //        index = i;
    //    }
    //}
    ////cout << endl << endl << endl;
    //visszalepesszamolas(index);
    //cout << maxx << ' ' << k << endl;
    //cout << t[index].index << ' ';
    //visszalepes(index);
    munka2();
    cout << db6 << ' ' << sdt.size() << endl;
    for (int i = 0; i < sdt.size(); i++) {
        cout << sdt[i].index << ' ';
    }


}

SubtaskSumTestVerdictTimeMemory
subtask10/0
1Partially correct1ms316 KiB
2Time limit exceeded681ms2356 KiB
subtask20/10
3Wrong answer1ms316 KiB
4Partially correct1ms316 KiB
5Wrong answer1ms392 KiB
6Wrong answer1ms316 KiB
7Wrong answer1ms316 KiB
subtask30/10
8Wrong answer1ms500 KiB
9Partially correct1ms316 KiB
10Wrong answer1ms316 KiB
11Wrong answer1ms500 KiB
12Wrong answer1ms356 KiB
subtask40/10
13Wrong answer1ms316 KiB
14Partially correct1ms316 KiB
15Wrong answer1ms392 KiB
16Wrong answer1ms316 KiB
17Wrong answer1ms316 KiB
18Wrong answer1ms316 KiB
19Wrong answer1ms316 KiB
20Wrong answer1ms316 KiB
21Wrong answer1ms316 KiB
22Wrong answer1ms316 KiB
subtask50/10
23Wrong answer1ms500 KiB
24Partially correct1ms316 KiB
25Wrong answer1ms316 KiB
26Wrong answer1ms500 KiB
27Wrong answer1ms356 KiB
28Wrong answer1ms316 KiB
29Wrong answer1ms316 KiB
30Wrong answer1ms316 KiB
31Wrong answer1ms316 KiB
32Wrong answer1ms316 KiB
subtask60/10
33Wrong answer1ms316 KiB
34Partially correct1ms316 KiB
35Wrong answer1ms392 KiB
36Wrong answer1ms316 KiB
37Wrong answer1ms316 KiB
38Wrong answer1ms500 KiB
39Partially correct1ms316 KiB
40Wrong answer1ms316 KiB
41Wrong answer1ms500 KiB
42Wrong answer1ms356 KiB
43Wrong answer1ms316 KiB
44Wrong answer1ms316 KiB
45Wrong answer1ms316 KiB
46Wrong answer1ms316 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 answer1ms316 KiB
subtask70/10
58Wrong answer1ms316 KiB
59Partially correct1ms316 KiB
60Wrong answer1ms392 KiB
61Wrong answer1ms316 KiB
62Wrong answer1ms316 KiB
63Wrong answer1ms500 KiB
64Partially correct1ms316 KiB
65Wrong answer1ms316 KiB
66Wrong answer1ms500 KiB
67Wrong answer1ms356 KiB
68Wrong answer1ms316 KiB
69Wrong answer1ms316 KiB
70Wrong answer1ms316 KiB
71Wrong answer1ms316 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 answer1ms316 KiB
83Time limit exceeded699ms1452 KiB
84Time limit exceeded699ms1500 KiB
85Time limit exceeded699ms1456 KiB
86Time limit exceeded699ms1452 KiB
87Time limit exceeded676ms1452 KiB
subtask80/20
88Wrong answer1ms316 KiB
89Partially correct1ms316 KiB
90Wrong answer1ms392 KiB
91Wrong answer1ms316 KiB
92Wrong answer1ms316 KiB
93Wrong answer1ms500 KiB
94Partially correct1ms316 KiB
95Wrong answer1ms316 KiB
96Wrong answer1ms500 KiB
97Wrong answer1ms356 KiB
98Wrong answer1ms316 KiB
99Wrong answer1ms316 KiB
100Wrong answer1ms316 KiB
101Wrong answer1ms316 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 answer1ms316 KiB
113Time limit exceeded699ms1452 KiB
114Time limit exceeded699ms1500 KiB
115Time limit exceeded699ms1456 KiB
116Time limit exceeded699ms1452 KiB
117Time limit exceeded676ms1452 KiB
118Time limit exceeded676ms2352 KiB
119Time limit exceeded676ms2356 KiB
120Time limit exceeded676ms2356 KiB
121Time limit exceeded676ms2336 KiB
122Time limit exceeded680ms2356 KiB
123Time limit exceeded680ms2372 KiB
124Time limit exceeded680ms2356 KiB
125Time limit exceeded680ms2364 KiB
126Time limit exceeded688ms2356 KiB
127Time limit exceeded686ms2372 KiB