88952024-02-03 10:31:49hackemonKombináció (50)cpp17Wrong answer 32/503ms4104 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); 

    for(int i = 0;i < k;i++ ) {
        cin >> a[i];
        b[i] = a[i];
    }
    
    int pos = 0; 

    for(int i = k-1;i >= 0;i-- ) {
        if(a[i] + 1 <= n) {
            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; 
    }

    for(int i = 0;i < k;i++ ) { 
        cout << b[i] << ' ';
    }
    cout << endl;
    for(int i = 0;i < k;i++ ) { 
        cout << a[i] << ' ';
    }   
    cout << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base32/50
1Accepted0/03ms1808 KiB
2Accepted0/03ms2028 KiB
3Wrong answer0/23ms2240 KiB
4Accepted2/23ms2456 KiB
5Partially correct1/23ms2708 KiB
6Partially correct1/23ms2940 KiB
7Accepted2/23ms2784 KiB
8Wrong answer0/23ms2816 KiB
9Partially correct1/23ms2920 KiB
10Partially correct2/43ms3060 KiB
11Partially correct2/43ms3240 KiB
12Accepted4/43ms3504 KiB
13Accepted4/43ms3556 KiB
14Wrong answer0/43ms3804 KiB
15Accepted4/43ms3984 KiB
16Partially correct3/63ms3972 KiB
17Accepted6/63ms4104 KiB