168022025-05-13 14:38:52AblablablaÖsszegzésekcpp17Accepted 100/10017ms1368 KiB
#include <iostream>
#include <vector>
using namespace std;
int main()
{
    int n, s, x, t, u;
    vector<int> a, b, o;
    s = 0;
    cin >> n;
    for (int i = 0; i < n; i++)
    {
        cin >> x;
        a.push_back(x);
        b.push_back(x);
        o.push_back(x);
        s += x;
    }
    //find one higher
    //method: go from end, find smallest number that neighbors one that is bigger, increment it and save its location
    //but: never can be the last number: cant add ones
    //so we start later
    //also end before 0: dont want overindexing
    //if none found: increment first
    //solution: copy everything until location, then spam 1 until sum = s
    if (o.size() != 1)
    {
        int z = s - a[a.size() - 1];
        int loc = 0;
        for (int i = a.size() - 2; i > 0; i--)
        {
            if (a[i] < a[i - 1])
            {
                loc = i;
                break;
            }
            else
            {
                z -= a[i];
            }
        }
        a[loc]++;
        z++;
        a.resize(loc + 1);
        for (int i = 0; i < s - z; i++)
        {
            a.push_back(1);
        }
        for (int i = 0; i < a.size(); i++)
        {
            cout << a[i] << " ";
        }
        cout << "\n";
    } else{
        cout << "0\n";
    }

    //find one lower (earlier)
    //method: drop first non-one value by one, add last value until reaching sum
    //sum is same, but lexicographically lower now

    int poz = -1;
    for (int i = b.size() - 1; i >= 0; i--)
    {
        if (b[i] > 1)
        {
            b[i]--;
            poz = i;
            break;
        }
    }

    if(poz != -1){
        int eddig = 0;
        for(int i = 0; i <= poz; i++){
            cout << b[i] << " ";
            eddig += b[i];
        }

        while(eddig + b[poz] < s){
            cout << b[poz] << " ";
            eddig += b[poz];
        }

        if(eddig != s){
            cout << s - eddig << "\n";
        }
    } else{
        cout << "0\n";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
3Accepted2ms316 KiB
subtask26/6
4Accepted1ms316 KiB
5Accepted1ms316 KiB
6Accepted1ms316 KiB
7Accepted1ms508 KiB
8Accepted1ms316 KiB
subtask36/6
9Accepted1ms316 KiB
10Accepted1ms316 KiB
11Accepted1ms316 KiB
12Accepted4ms564 KiB
13Accepted4ms564 KiB
subtask410/10
14Accepted1ms316 KiB
15Accepted1ms316 KiB
16Accepted1ms316 KiB
17Accepted4ms564 KiB
18Accepted4ms564 KiB
19Accepted1ms316 KiB
20Accepted2ms316 KiB
21Accepted16ms1368 KiB
22Accepted17ms1320 KiB
23Accepted16ms1300 KiB
subtask510/10
24Accepted1ms508 KiB
25Accepted1ms508 KiB
26Accepted1ms316 KiB
27Accepted1ms316 KiB
28Accepted1ms508 KiB
subtask610/10
29Accepted1ms316 KiB
30Accepted1ms316 KiB
31Accepted1ms316 KiB
32Accepted1ms316 KiB
33Accepted1ms316 KiB
subtask758/58
34Accepted1ms316 KiB
35Accepted1ms316 KiB
36Accepted1ms316 KiB
37Accepted1ms316 KiB
38Accepted1ms316 KiB
39Accepted1ms316 KiB
40Accepted1ms508 KiB
41Accepted1ms316 KiB
42Accepted1ms316 KiB
43Accepted1ms316 KiB
44Accepted1ms316 KiB
45Accepted4ms564 KiB
46Accepted4ms564 KiB
47Accepted1ms316 KiB
48Accepted2ms316 KiB
49Accepted16ms1368 KiB
50Accepted17ms1320 KiB
51Accepted1ms508 KiB
52Accepted1ms316 KiB
53Accepted1ms316 KiB
54Accepted1ms316 KiB
55Accepted1ms316 KiB
56Accepted1ms316 KiB
57Accepted1ms316 KiB
58Accepted1ms508 KiB
59Accepted1ms316 KiB
60Accepted1ms316 KiB
61Accepted1ms316 KiB
62Accepted1ms316 KiB
63Accepted2ms436 KiB
64Accepted2ms316 KiB
65Accepted3ms316 KiB
66Accepted4ms564 KiB