234802026-01-23 17:03:58tamasnagyDíjazás több helyezettnekcpp17Accepted 80/804ms600 KiB
// dijazasTobbFasszal.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
using namespace std;
vector <int> sor;
int hely, ered;

void kiir() {
    for (int i = 1; i <= hely; i++) {
        cout << sor[i] << ' ';
    }
    cout << endl;
}

bool hellye() {
    int sum = 0;
    for (int i = 1; i <= hely; i++) {
        sum += sor[i];
    }
    if (sum == ered) {
        //cout << sum + sor[hely - 1] << endl;
        return true;
    }
    return false;
}

void solve(int h, int e, int depth = 1) {
    //kiir();
    int mini, maxi;
    maxi = e - (h * (h - 1) / 2);
    mini = hely - depth + 1;
    //cout << mini <<" "<< maxi <<" "<< depth << endl;
    for (int i = maxi; i >= mini; i--) {
        if (sor[depth - 1] > i) {
            sor[depth] = i;
            if (depth <= hely) {
                solve(h - 1, e - i, depth+1);
            }
            else {
                if (hellye()) {
                    kiir();
                }
            }
        }
    }
    return;
}

int main()
{
    cin >> hely >> ered;
    sor.push_back(ered);
    sor.resize(hely+2);
    solve(hely, ered);
}

// 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
2Accepted2ms316 KiB
subtask25/5
3Accepted1ms316 KiB
4Accepted1ms500 KiB
5Accepted1ms316 KiB
6Accepted1ms316 KiB
7Accepted1ms316 KiB
subtask35/5
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms508 KiB
12Accepted4ms316 KiB
subtask415/15
13Accepted1ms492 KiB
14Accepted1ms500 KiB
15Accepted1ms508 KiB
16Accepted2ms316 KiB
17Accepted3ms316 KiB
subtask515/15
18Accepted1ms316 KiB
19Accepted2ms356 KiB
20Accepted2ms316 KiB
21Accepted2ms316 KiB
22Accepted1ms316 KiB
subtask615/15
23Accepted1ms316 KiB
24Accepted3ms600 KiB
25Accepted1ms316 KiB
26Accepted2ms356 KiB
27Accepted2ms316 KiB
28Accepted2ms316 KiB
29Accepted1ms316 KiB
30Accepted4ms500 KiB
31Accepted3ms316 KiB
32Accepted1ms316 KiB
33Accepted1ms316 KiB
34Accepted3ms316 KiB
35Accepted1ms316 KiB
36Accepted1ms316 KiB
37Accepted3ms316 KiB
38Accepted4ms332 KiB
39Accepted1ms316 KiB
subtask725/25
40Accepted1ms316 KiB
41Accepted3ms600 KiB
42Accepted1ms316 KiB
43Accepted1ms500 KiB
44Accepted1ms316 KiB
45Accepted1ms316 KiB
46Accepted1ms316 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms316 KiB
50Accepted1ms508 KiB
51Accepted4ms316 KiB
52Accepted1ms492 KiB
53Accepted1ms500 KiB
54Accepted1ms508 KiB
55Accepted2ms316 KiB
56Accepted3ms316 KiB
57Accepted1ms316 KiB
58Accepted2ms356 KiB
59Accepted2ms316 KiB
60Accepted2ms316 KiB
61Accepted1ms316 KiB
62Accepted4ms500 KiB
63Accepted3ms316 KiB
64Accepted1ms316 KiB
65Accepted1ms316 KiB
66Accepted3ms316 KiB
67Accepted1ms316 KiB
68Accepted1ms316 KiB
69Accepted3ms316 KiB
70Accepted4ms332 KiB
71Accepted1ms316 KiB
72Accepted3ms332 KiB
73Accepted1ms316 KiB
74Accepted3ms316 KiB
75Accepted1ms348 KiB
76Accepted1ms316 KiB
77Accepted3ms552 KiB
78Accepted1ms316 KiB
79Accepted2ms316 KiB
80Accepted1ms500 KiB
81Accepted3ms316 KiB