98832024-03-14 19:00:19GervidKombináció (50)cpp17Accepted 50/503ms4392 KiB
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <limits.h>
#include <algorithm>
#include <math.h>

using namespace std;

int main()
{
	iostream::sync_with_stdio(0);
	cin.tie(0);

	int n, m, i, j;
	cin >> n >> m;

	vector<int> vec(m);
	for (i = 0; i < m; i++)
	{
		cin >> vec[i];
	}

	//previous
	for (i = m-1; i > 0; i--)
	{
		if (vec[i] > vec[i-1] + 1)
		{
			for (j = 0; j < i; j++)
			{
				cout << vec[j] << ' ';
			}
			cout << vec[j] - 1 << ' ';
			for (j++; j < m; j++)
			{
				cout << n - m + j + 1 << ' ';
			}
			cout << '\n';

			break;
		}
	}
	if (i == 0) //need to decrement first index || vec is the first one
	{
		j = 1;
		if (vec[0] > 1)
		{
			cout << vec[0] - 1 << ' ';
			j++;
		}
		for (; j <= m; j++)
		{
			cout << n - m + j << ' ';
		}
		cout << '\n';
	}

	//next
	if (vec.back() < n)
	{
		for (i = 0; i < m-1; i++) cout << vec[i] << ' ';
		cout << vec.back() + 1;

		return 0;
	}

	for (i = m-2; i > -1; i--)
	{
		if (vec[i] + 1 < vec[i+1])
		{
			for (j = 0; j < i; j++) cout << vec[j] << ' ';
			cout << vec[i] + 1 << ' ';
			for (j = i + 1; j < m; j++) cout << n - m + j + 1 << ' ';
			
			return 0;
		}
	}

	for (i = 1; i <= m; i++)
	{
		cout << i << ' ';
	}
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1972 KiB
2Accepted0/03ms2188 KiB
3Accepted2/23ms2408 KiB
4Accepted2/23ms2616 KiB
5Accepted2/23ms2640 KiB
6Accepted2/23ms2872 KiB
7Accepted2/23ms2924 KiB
8Accepted2/23ms3048 KiB
9Accepted2/23ms3244 KiB
10Accepted4/43ms3460 KiB
11Accepted4/43ms3684 KiB
12Accepted4/43ms3892 KiB
13Accepted4/43ms4072 KiB
14Accepted4/43ms4180 KiB
15Accepted4/43ms4228 KiB
16Accepted6/63ms4296 KiB
17Accepted6/63ms4392 KiB