98822024-03-14 18:57:49GervidKombináció (50)cpp17Wrong answer 41/503ms3472 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
base41/50
1Accepted0/03ms1976 KiB
2Wrong answer0/03ms2112 KiB
3Accepted2/22ms2196 KiB
4Accepted2/23ms2204 KiB
5Accepted2/23ms2264 KiB
6Accepted2/23ms2352 KiB
7Partially correct1/23ms2480 KiB
8Accepted2/22ms2488 KiB
9Accepted2/23ms2628 KiB
10Accepted4/43ms2836 KiB
11Partially correct2/43ms3052 KiB
12Accepted4/43ms3136 KiB
13Accepted4/43ms3244 KiB
14Accepted4/43ms3372 KiB
15Accepted4/43ms3464 KiB
16Partially correct3/63ms3464 KiB
17Partially correct3/63ms3472 KiB