-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path198-beautiful-palindromes.cpp
More file actions
50 lines (47 loc) · 1.14 KB
/
Copy path198-beautiful-palindromes.cpp
File metadata and controls
50 lines (47 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
/*
* Beautiful Palindromes [2162E]
* Problem: https://codeforces.com/problemset/problem/2162/E
* Verdict: ACCEPTED Solved: 2025-10-19
* Language: C++20 (GCC 13-64)
* Runtime: 124 ms Memory: 2500 KB
* Tags: constructive algorithms, greedy, schedules
* Author: team "balls" (HossamIsmail, BidoTeima, a1abay)
* Source: https://codeforces.com/contest/2162/submission/344577096
*/
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n,k;
cin >>n>>k;
vector<int> v(n), freq(n+1);
for(int i=0; i<n; i++){
cin >> v[i];
freq[v[i]]++;
}
for(int i=1; i<=n; i++){
if(freq[i] == 0) {v.push_back(i); break;}
}
for(int i=v.size(); i<=n+k; i++){
int tmp = 1;
if(v[i-1] == 1 || v[i-2] == 1){
if(v[i-1] == 2 || v[i-2] == 2){
tmp=3;
}
else tmp=2;
}
v.push_back(tmp);
}
for(int i=n; i<=n+k-1; i++){
cout << v[i] << " ";
}
cout << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cout.tie(NULL);
int t=1;
cin >> t;
while(t--)
solve();
return 0;
}