# |
Author |
Problem |
Lang |
Verdict |
Time |
Memory |
Sent |
Judged |
|
78739940 |
Contestant:
LaKsHiTh_ |
1348C
- 44
|
GNU C++17
|
Accepted
|
1388 ms
|
4900 KB
|
2020-05-01 19:53:23 |
2020-05-01 20:57:38 |
|
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef pair<db,db> pd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<db> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORi(i,a,b) for(int i=(a);i>=(b);i--)
#define FORZ(i,a) for(int i=0;i<(a);i++)
#define FORZi(i,a) for(int i=(a)-1;i>=0;i--)
#define trav(a,x) for (auto& a: x)
#define what_is(x) cout << #x << " is " << x << "\n";
#define printl(a) cout << a << "\n";
#define prints(a) cout << a << " ";
#define printall(x) FORZ(i,sz(x))prints(x[i])
#define nextl cout << "\n"
#define in(a) cin >> a;
inline void io_setup(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
int main(){
io_setup();
int t;
in(t);
while(t--){
int n,k;
vector<char> vec;
cin >> n;
cin >> k;
// string s;
// cin >> s;
FORZ(i,n){
char a;
cin >> a;
vec.pb(a);
}
sort(vec.begin(),vec.end());
int lastIndex = vec.size()-1;
char lastChar = vec.at(lastIndex);
int i;
for(i=lastIndex;i>=0;i--){
if(vec.at(i)!=lastChar)break;
}
lastIndex = max(i+1,k);
// what_is(lastIndex);
if(lastIndex!=k)lastIndex=vec.size();
priority_queue <string ,vector<string>, greater<string>> pq;
for(int i=0;i<k;i++){
string temp = "";
temp += vec.at(i);
pq.push(temp);
}
string temp = pq.top();
for(int i=k;i<lastIndex;i++){
temp += vec.at(i);
// what_is(i);
// string temp = pq.top();
// temp += vec.at(i);
// what_is(temp);
}
// what_is(temp);
pq.pop();
pq.push(temp);
for(int i=lastIndex;i<vec.size();i++){
string temp = pq.top();
temp += vec.at(i);
pq.pop();
pq.push(temp);
}
string MAX;
while(pq.empty()==false){
MAX = pq.top();
pq.pop();
}
printl(MAX);
}
}
/*
`-. .-'
: :
--:--:--
: :
.-' `-. ~LaKsHiTh_
*/
Click to see test details