Codeforces Round 921 (Div. 2) 1925C. Did We Get Everything Covered? Solution
Problem Link : https://codeforces.com/contest/1925/problem/C
Solution in C++:
- /// Author : AH_Tonmoy
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t;
- cin >> t;
- while (t--) {
- int n , k , m ; cin >> n >> k >> m ;
- string s ; cin >> s ;
- string ans ="";
- set<char>st ;
- for (int i = 0 ; i < m ; i++){
- st.insert(s[i]) ;
- if(st.size() == k ){
- ans +=s[i] ;
- st.clear() ;
- }
- }
- if(ans.size() >= n){
- cout <<"YES\n";
- }
- else{
- cout <<"NO\n" ;
- char mis_ch ;
- for( int i = 0 ; i < k ; i++){
- char c = (char)('a'+i) ;
- if(st.count(c) == 0){
- mis_ch = c ;
- break ;
- }
- }
- while(ans.size() < n) {
- ans += mis_ch ;
- }
- cout << ans <<'\n';
- }
- }
- return 0 ;
- }
No comments