168492025-05-14 08:13:35TortelliniJrÖsszegzésekcpp17Hibás válasz 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";
    }
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva1ms316 KiB
2Elfogadva1ms316 KiB
3Elfogadva1ms316 KiB
subtask20/6
4Hibás válasz1ms328 KiB
5Részben helyes1ms316 KiB
6Részben helyes1ms508 KiB
7Részben helyes1ms316 KiB
8Részben helyes1ms316 KiB
subtask33/6
9Részben helyes1ms316 KiB
10Részben helyes1ms316 KiB
11Részben helyes1ms500 KiB
12Részben helyes4ms564 KiB
13Részben helyes4ms568 KiB
subtask45/10
14Részben helyes1ms316 KiB
15Részben helyes1ms316 KiB
16Részben helyes1ms500 KiB
17Részben helyes4ms564 KiB
18Részben helyes4ms568 KiB
19Elfogadva1ms316 KiB
20Elfogadva2ms316 KiB
21Elfogadva16ms1328 KiB
22Elfogadva17ms1328 KiB
23Elfogadva16ms1200 KiB
subtask510/10
24Elfogadva1ms508 KiB
25Elfogadva1ms316 KiB
26Elfogadva1ms508 KiB
27Elfogadva1ms316 KiB
28Elfogadva1ms316 KiB
subtask610/10
29Elfogadva1ms316 KiB
30Elfogadva1ms316 KiB
31Elfogadva1ms316 KiB
32Elfogadva1ms316 KiB
33Elfogadva1ms316 KiB
subtask70/58
34Elfogadva1ms316 KiB
35Elfogadva1ms316 KiB
36Elfogadva1ms316 KiB
37Hibás válasz1ms328 KiB
38Részben helyes1ms316 KiB
39Részben helyes1ms508 KiB
40Részben helyes1ms316 KiB
41Részben helyes1ms316 KiB
42Részben helyes1ms316 KiB
43Részben helyes1ms316 KiB
44Részben helyes1ms500 KiB
45Részben helyes4ms564 KiB
46Részben helyes4ms568 KiB
47Elfogadva1ms316 KiB
48Elfogadva2ms316 KiB
49Elfogadva16ms1328 KiB
50Elfogadva17ms1328 KiB
51Elfogadva1ms316 KiB
52Elfogadva1ms316 KiB
53Elfogadva1ms316 KiB
54Elfogadva1ms316 KiB
55Elfogadva1ms316 KiB
56Elfogadva1ms316 KiB
57Elfogadva1ms316 KiB
58Elfogadva1ms316 KiB
59Elfogadva1ms316 KiB
60Elfogadva1ms316 KiB
61Elfogadva1ms316 KiB
62Elfogadva2ms316 KiB
63Elfogadva2ms316 KiB
64Elfogadva2ms316 KiB
65Elfogadva3ms420 KiB
66Elfogadva4ms612 KiB