168492025-05-14 08:13:35TortelliniJrÖsszegzésekcpp17Wrong answer 28/10017ms1328 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);
        }
    }
    //find one lower (earlier)
    //method: drop first non-one value by one, proceed to append one to the last number we can "legally" add to, if none then append zero
    //sum is same, but lexicographically lower now
    int l = 0;
    for (int i = b.size() - 1; i >= 0; i--)
    {
        if (b[i] != 1)
        {
            b[i]--;
            l = i;
            break;
        }
    }
    bool flag = false;
    for (int i = l + 1; i < b.size(); i++)
    {
        if (b[i] < b[i - 1])
        {
            b[i]++;
            flag = true;
            break;
        }
    }
    if (!flag)
    {
        b.push_back(1);
    }
    //output time!
    for (int i = 0; i < a.size(); i++)
    {
        cout << a[i] << " ";
    }
    cout << endl;
    if (b != o)
    {
        for (int i = 0; i < b.size(); i++)
        {
            cout << b[i] << " ";
        }
    }
    else
    {
        cout << "0";
    }
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted1ms316 KiB
2Accepted1ms316 KiB
3Accepted1ms316 KiB
subtask20/6
4Wrong answer1ms328 KiB
5Partially correct1ms316 KiB
6Partially correct1ms508 KiB
7Partially correct1ms316 KiB
8Partially correct1ms316 KiB
subtask33/6
9Partially correct1ms316 KiB
10Partially correct1ms316 KiB
11Partially correct1ms500 KiB
12Partially correct4ms564 KiB
13Partially correct4ms568 KiB
subtask45/10
14Partially correct1ms316 KiB
15Partially correct1ms316 KiB
16Partially correct1ms500 KiB
17Partially correct4ms564 KiB
18Partially correct4ms568 KiB
19Accepted1ms316 KiB
20Accepted2ms316 KiB
21Accepted16ms1328 KiB
22Accepted17ms1328 KiB
23Accepted16ms1200 KiB
subtask510/10
24Accepted1ms508 KiB
25Accepted1ms316 KiB
26Accepted1ms508 KiB
27Accepted1ms316 KiB
28Accepted1ms316 KiB
subtask610/10
29Accepted1ms316 KiB
30Accepted1ms316 KiB
31Accepted1ms316 KiB
32Accepted1ms316 KiB
33Accepted1ms316 KiB
subtask70/58
34Accepted1ms316 KiB
35Accepted1ms316 KiB
36Accepted1ms316 KiB
37Wrong answer1ms328 KiB
38Partially correct1ms316 KiB
39Partially correct1ms508 KiB
40Partially correct1ms316 KiB
41Partially correct1ms316 KiB
42Partially correct1ms316 KiB
43Partially correct1ms316 KiB
44Partially correct1ms500 KiB
45Partially correct4ms564 KiB
46Partially correct4ms568 KiB
47Accepted1ms316 KiB
48Accepted2ms316 KiB
49Accepted16ms1328 KiB
50Accepted17ms1328 KiB
51Accepted1ms316 KiB
52Accepted1ms316 KiB
53Accepted1ms316 KiB
54Accepted1ms316 KiB
55Accepted1ms316 KiB
56Accepted1ms316 KiB
57Accepted1ms316 KiB
58Accepted1ms316 KiB
59Accepted1ms316 KiB
60Accepted1ms316 KiB
61Accepted1ms316 KiB
62Accepted2ms316 KiB
63Accepted2ms316 KiB
64Accepted2ms316 KiB
65Accepted3ms420 KiB
66Accepted4ms612 KiB