195912025-12-16 10:48:36gkataDíjazás több helyezettnekcpp17Accepted 80/8032ms512 KiB

// dijazas.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <queue>
#define ll long long

using namespace std;

ll n, p, s=0;
vector<ll>x;

void kiir(int m)
{
    for (int j = 1; j <= m; ++j)
        cout << x[j] << " ";
   cout << endl;
}

void back(int k, int a, int b)
{
    int mx = b - ((a - 1) * a) / 2;
    int mn = b / a;
    for (int i = mx; i >= mn; --i)
    {
        if (s + i <= n && i < x[k - 1])
        {
            x[k] = i;
            s += i;
            if (s == n)
            {
                if(k == p) kiir(p);
            }
            else  back(k + 1, a - 1, b - i);
            s -= i;
        }
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> p >> n;
    x.resize(p + 1);

    x[0] = n - ((p - 1) * p) / 2 + 1;

    back(1,p,n);
}

// 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
4Accepted1ms508 KiB
5Accepted1ms316 KiB
6Accepted1ms316 KiB
7Accepted1ms316 KiB
subtask35/5
8Accepted1ms316 KiB
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms332 KiB
12Accepted2ms316 KiB
subtask415/15
13Accepted1ms368 KiB
14Accepted1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms332 KiB
17Accepted2ms376 KiB
subtask515/15
18Accepted1ms376 KiB
19Accepted2ms316 KiB
20Accepted2ms316 KiB
21Accepted2ms500 KiB
22Accepted1ms316 KiB
subtask615/15
23Accepted1ms316 KiB
24Accepted3ms316 KiB
25Accepted1ms376 KiB
26Accepted2ms316 KiB
27Accepted2ms316 KiB
28Accepted2ms500 KiB
29Accepted1ms316 KiB
30Accepted3ms424 KiB
31Accepted2ms316 KiB
32Accepted1ms316 KiB
33Accepted1ms316 KiB
34Accepted3ms316 KiB
35Accepted1ms316 KiB
36Accepted2ms316 KiB
37Accepted4ms508 KiB
38Accepted4ms316 KiB
39Accepted2ms316 KiB
subtask725/25
40Accepted1ms316 KiB
41Accepted3ms316 KiB
42Accepted1ms316 KiB
43Accepted1ms508 KiB
44Accepted1ms316 KiB
45Accepted1ms316 KiB
46Accepted1ms316 KiB
47Accepted1ms316 KiB
48Accepted1ms316 KiB
49Accepted1ms316 KiB
50Accepted1ms332 KiB
51Accepted2ms316 KiB
52Accepted1ms368 KiB
53Accepted1ms316 KiB
54Accepted1ms316 KiB
55Accepted1ms332 KiB
56Accepted2ms376 KiB
57Accepted1ms376 KiB
58Accepted2ms316 KiB
59Accepted2ms316 KiB
60Accepted2ms500 KiB
61Accepted1ms316 KiB
62Accepted3ms424 KiB
63Accepted2ms316 KiB
64Accepted1ms316 KiB
65Accepted1ms316 KiB
66Accepted3ms316 KiB
67Accepted1ms316 KiB
68Accepted2ms316 KiB
69Accepted4ms508 KiB
70Accepted4ms316 KiB
71Accepted2ms316 KiB
72Accepted12ms512 KiB
73Accepted3ms512 KiB
74Accepted16ms508 KiB
75Accepted2ms500 KiB
76Accepted2ms316 KiB
77Accepted24ms316 KiB
78Accepted2ms316 KiB
79Accepted32ms316 KiB
80Accepted4ms316 KiB
81Accepted10ms508 KiB