-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1422.cpp
60 lines (44 loc) · 816 Bytes
/
1422.cpp
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
51
52
53
54
55
56
57
58
59
60
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
string arr[1001];
string arr2[1001];
bool Decending(string a, string b) {
if (a.length() == b.length()) {
return a > b;
}
return a.length() > b.length();
}
bool Decending2(string a, string b) {
string A, B;
A.append(a);
A.append(b);
B.append(b);
B.append(a);
return A > B;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int K, N;
cin >> K >> N;
for (int i = 0; i < K; ++i) {
cin >> arr[i];
}
sort(arr, arr + K, Decending);
for (int i = 0; i < K; ++i) {
arr2[i] = arr[i];
}
for (int i = K; i < N; ++i) {
arr2[i] = arr[0];
}
sort(arr2, arr2 + N, Decending2);
string answer;
for (int i = 0; i < N; ++i) {
answer.append(arr2[i]);
}
cout << answer;
return 0;
}