88972024-02-03 11:05:03hackemonKombináció (50)cpp17Accepted 50/503ms3992 KiB
#include <bits/stdc++.h>
using namespace std;



int main()
{
    //freopen("be2.txt", "r", stdin);
    //freopen("ki.txt", "w", stdout);

    int n, k;
    cin >> n >> k;

    vector<int> a(k), b(k); 

    bool checker1 = true, checker2 = true;

    for(int i = 0;i < k;i++ ) {
        cin >> a[i];
        b[i] = a[i];
        if(a[i] != i+1) checker1 = false;
        if(a[i] != n - k + i + 1) checker2 = false;
    }
    
    int pos = 0; 
    if(a[k - 1] + 1 <= n) {
            pos = k - 1; 
    } else {
    for(int i = k-2;i > 0;i-- ) {
        if(a[i + 1] - 1  >  a[i]) {
            pos = i; 
            break;
        }
    }
    }

    a[pos]++;

    for(int i = pos + 1;i < k;i++ ) {
        a[i] = a[i-1] + 1; 
    }
        
    for(int i = k-1;i > 0;i--) {
        if(b[i] - 1 > b[i-1]) {
            pos = i;
            break;
        } else if(i == 1) {
            pos = 0; 
        }
    }
    b[pos]--;

    
    for(int i = k - 1;i > pos;i-- ) {
        b[i] = n - k + i + 1; 
    }

    if(checker1) {
        for(int i = 0;i < k;i++ ) {
            cout << n - k  + i + 1 << ' ';
        }
    } else 
    for(int i = 0;i < k;i++ ) { 
        cout << b[i] << ' ';
    }
    cout << endl;
    if(checker2) {
        for(int i = 0;i < k;i++ ) {
            cout << i+1 << ' ';
        }
    } else 
    for(int i = 0;i < k;i++ ) { 
        cout << a[i] << ' ';
    }   
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1848 KiB
2Accepted0/03ms2004 KiB
3Accepted2/22ms2092 KiB
4Accepted2/23ms2124 KiB
5Accepted2/22ms2188 KiB
6Accepted2/23ms2440 KiB
7Accepted2/23ms2648 KiB
8Accepted2/23ms2860 KiB
9Accepted2/23ms2956 KiB
10Accepted4/43ms3200 KiB
11Accepted4/43ms3284 KiB
12Accepted4/43ms3248 KiB
13Accepted4/43ms3248 KiB
14Accepted4/43ms3404 KiB
15Accepted4/43ms3536 KiB
16Accepted6/63ms3748 KiB
17Accepted6/63ms3992 KiB