//
// main.cpp
// Praca
//
// Created by dzmitry kavaliou on 10/03/2025.
//
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[]) {
int n, k, t;
cin >> n >> k >> t;
int wan=0, to=0, sri=0;
int maxval = -1;
string s;
cin >> s;
for(int i = 0; i < n; i++){
if(s[i]=='1') wan++;
else if(s[i]=='2') to++;
else if(s[i]=='3') sri++;
}
if(wan <= k){
cout << min(sri + k, n) << endl;
}
else{
int o = 0;
int i = 0;
int maxi = 0;
for(;t+i <n-t-o;i++){
for(;t+i <n-t-o;o++){
int won = 0, too = 0, tri = 0,rtoo = 0;
int j = 0;
for(; j < i; j++){
if(s[j] == '3') tri++;
else if(s[j] == '2') rtoo++;
else if(s[j] == '1') won++;
}
for(; j < t+i; j++){
if(s[j] == '2') too++;
else if(s[j] == '1') won++;
}
for(j = n-t-o; j < n-o; j++){
if(s[j] == '2') too++;
else if(s[j] == '1') won++;
}
for(; j < n; j++){
if(s[j] == '3') tri++;
else if(s[j] == '2') rtoo++;
else if(s[j] == '1') won++;
}
if(too+won > k) continue;
else{
int val = min(tri+(k-(too+won)), tri+rtoo);
maxval = max(maxval, val);
}
}
o = 0;
}
cout << maxval << endl;
}
return 0;
}
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 61 62 63 64 | // // main.cpp // Praca // // Created by dzmitry kavaliou on 10/03/2025. // #include <iostream> #include <string> #include <cmath> using namespace std; int main(int argc, const char * argv[]) { int n, k, t; cin >> n >> k >> t; int wan=0, to=0, sri=0; int maxval = -1; string s; cin >> s; for(int i = 0; i < n; i++){ if(s[i]=='1') wan++; else if(s[i]=='2') to++; else if(s[i]=='3') sri++; } if(wan <= k){ cout << min(sri + k, n) << endl; } else{ int o = 0; int i = 0; int maxi = 0; for(;t+i <n-t-o;i++){ for(;t+i <n-t-o;o++){ int won = 0, too = 0, tri = 0,rtoo = 0; int j = 0; for(; j < i; j++){ if(s[j] == '3') tri++; else if(s[j] == '2') rtoo++; else if(s[j] == '1') won++; } for(; j < t+i; j++){ if(s[j] == '2') too++; else if(s[j] == '1') won++; } for(j = n-t-o; j < n-o; j++){ if(s[j] == '2') too++; else if(s[j] == '1') won++; } for(; j < n; j++){ if(s[j] == '3') tri++; else if(s[j] == '2') rtoo++; else if(s[j] == '1') won++; } if(too+won > k) continue; else{ int val = min(tri+(k-(too+won)), tri+rtoo); maxval = max(maxval, val); } } o = 0; } cout << maxval << endl; } return 0; } |
English