168472025-05-14 08:11:39TortelliniJrÖsszegzésekcpp17Részben helyes 21/10017ms1388 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;
        }
    }
    for (int i = l + 1; i < b.size(); i++)
    {
        if (b[i] < b[i - 1])
        {
            b[i]++;
            break;
        }
    }
    //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";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
2Részben helyes1ms316 KiB
3Részben helyes1ms316 KiB
subtask20/6
4Részben helyes1ms316 KiB
5Hibás válasz1ms316 KiB
6Hibás válasz1ms316 KiB
7Hibás válasz1ms316 KiB
8Hibás válasz1ms380 KiB
subtask36/6
9Elfogadva1ms316 KiB
10Elfogadva1ms316 KiB
11Elfogadva1ms316 KiB
12Elfogadva4ms564 KiB
13Elfogadva4ms564 KiB
subtask45/10
14Elfogadva1ms316 KiB
15Elfogadva1ms316 KiB
16Elfogadva1ms316 KiB
17Elfogadva4ms564 KiB
18Elfogadva4ms564 KiB
19Részben helyes1ms316 KiB
20Részben helyes2ms316 KiB
21Részben helyes16ms1240 KiB
22Részben helyes17ms1388 KiB
23Részben helyes16ms1184 KiB
subtask55/10
24Részben helyes1ms316 KiB
25Részben helyes1ms316 KiB
26Részben helyes1ms508 KiB
27Részben helyes1ms316 KiB
28Részben helyes1ms316 KiB
subtask65/10
29Részben helyes1ms548 KiB
30Részben helyes1ms500 KiB
31Részben helyes1ms316 KiB
32Részben helyes1ms316 KiB
33Részben helyes1ms316 KiB
subtask70/58
34Elfogadva1ms316 KiB
35Részben helyes1ms316 KiB
36Részben helyes1ms316 KiB
37Részben helyes1ms316 KiB
38Hibás válasz1ms316 KiB
39Hibás válasz1ms316 KiB
40Hibás válasz1ms316 KiB
41Hibás válasz1ms380 KiB
42Elfogadva1ms316 KiB
43Elfogadva1ms316 KiB
44Elfogadva1ms316 KiB
45Elfogadva4ms564 KiB
46Elfogadva4ms564 KiB
47Részben helyes1ms316 KiB
48Részben helyes2ms316 KiB
49Részben helyes16ms1240 KiB
50Részben helyes17ms1388 KiB
51Részben helyes1ms316 KiB
52Részben helyes1ms548 KiB
53Részben helyes1ms500 KiB
54Részben helyes1ms316 KiB
55Részben helyes1ms316 KiB
56Részben helyes1ms316 KiB
57Részben helyes1ms316 KiB
58Részben helyes1ms316 KiB
59Részben helyes1ms408 KiB
60Részben helyes1ms316 KiB
61Részben helyes1ms316 KiB
62Részben helyes1ms392 KiB
63Részben helyes2ms316 KiB
64Részben helyes2ms316 KiB
65Részben helyes3ms316 KiB
66Részben helyes4ms564 KiB