109642024-04-22 15:32:48VargusKombináció (50)cpp17Wrong answer 35/503ms4016 KiB
#include <iostream>
#include <queue>
#define ll long long

using namespace std;

vector <ll> x, y, z;
ll n, k;

bool jo(ll lep)
{
    if (y[lep - 1] <= y[lep] && y[lep] >= x[lep])
        return true;
    return false;
}

int main()
{
    cin >> n >> k;
    x.resize(k + 1);
    y.resize(k + 1);
    z.resize(k + 1);
    for (ll i = 1; i <= k; ++i)
    {
        cin >> x[i];
        y[i] = x[i];
        z[i] = x[i];
    }
    ll n1 = n, db = 0;
    for (ll i = k; i >= 1; --i)
    {
        if (y[i] == n1)
        {
            ++db;
            --n1;
        }
        else
        {
            ++y[i];
            for (ll j = i + 1; j <= k; ++j)
            {
                for (ll g = 1; g <= n; ++g)
                {
                    y[j] = g;
                    if (jo(j))
                        break;
                }
            }
            break;
        }
    }

    bool ok = false;
    for (ll i = 1; i <= k; ++i)
    {
        n1 = n - k + i;
        if (z[i] == n1)
        {
            z[i]--;
            ok = true;
            break;
        }
    }
    if (!ok)
    {
        z[1]--;
        for (ll i = 2; i <= k; ++i)
            z[i]++;
    }

    for (ll i = 1; i <= k; ++i)
        cout << z[i] << " ";

    cout << "\n";
    for (ll i = 1; i <= k; ++i)
        cout << y[i] << " ";

    return 0;
}
/*
6 4
1 2 4 6
*/
SubtaskSumTestVerdictTimeMemory
base35/50
1Accepted0/03ms1752 KiB
2Wrong answer0/03ms2000 KiB
3Partially correct1/23ms2076 KiB
4Accepted2/23ms2372 KiB
5Partially correct1/23ms2420 KiB
6Partially correct1/23ms2516 KiB
7Partially correct1/23ms2572 KiB
8Partially correct1/23ms2784 KiB
9Partially correct1/23ms3148 KiB
10Partially correct2/43ms3268 KiB
11Accepted4/43ms3356 KiB
12Accepted4/43ms3476 KiB
13Accepted4/43ms3552 KiB
14Partially correct2/43ms3688 KiB
15Partially correct2/43ms3772 KiB
16Accepted6/63ms3904 KiB
17Partially correct3/63ms4016 KiB