#include <bits/stdc++.h>
//#include <cassert>
const int inf = 2e9;
const long long ill = 4e18;
const long long mod = 998244353;
const long double eps = 1e-6;
#define pii pair<int, int>
#define tui tuple<int, int, ll>
typedef long long ll;
typedef long double ld;
using namespace std;
void solve() {
int n, skip, t;
cin >> n >> skip >> t;
vector<int> total(n + 1), work(n + 1), remote(n + 1);
string s;
cin >> s;
for (int i = 0; i < n; i++) {
if (s[i] == '1' || s[i] == '2')
total[i + 1] = total[i] + 1;
else
total[i + 1] = total[i];
if (s[i] == '1')
work[i + 1] = work[i] + 1;
else
work[i + 1] = work[i];
if (s[i] == '2')
remote[i + 1] = remote[i] + 1;
else
remote[i + 1] = remote[i];
}
int meetings = total[n];
int mx = -inf;
// bobr is at work on [l,r]
for (int r = t; r < n - t; r++) {
for (int l = t; l <= r; l++) {
// in how many meetings can participate
int can = remote[l - t] - remote[0] + total[r + 1] - total[l] + remote[n] - remote[r + t + 1]; // remote[0]=total[0]=work[0]=0
if (can >= meetings - skip) {
int wm = total[r + 1] - total[l];
int rm = max(0, meetings - skip - wm);
mx = max(mx, l - t + n - (r + t + 1) - rm);
}
}
}
if (remote[n] >= meetings - skip) {
mx = max(mx, n - max(0, meetings - skip));
}
if (mx == -inf)
mx = -1;
cout << mx << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);
int t = 1;
//cin >> t;
while (t--)
solve();
}
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 65 66 67 | #include <bits/stdc++.h> //#include <cassert> const int inf = 2e9; const long long ill = 4e18; const long long mod = 998244353; const long double eps = 1e-6; #define pii pair<int, int> #define tui tuple<int, int, ll> typedef long long ll; typedef long double ld; using namespace std; void solve() { int n, skip, t; cin >> n >> skip >> t; vector<int> total(n + 1), work(n + 1), remote(n + 1); string s; cin >> s; for (int i = 0; i < n; i++) { if (s[i] == '1' || s[i] == '2') total[i + 1] = total[i] + 1; else total[i + 1] = total[i]; if (s[i] == '1') work[i + 1] = work[i] + 1; else work[i + 1] = work[i]; if (s[i] == '2') remote[i + 1] = remote[i] + 1; else remote[i + 1] = remote[i]; } int meetings = total[n]; int mx = -inf; // bobr is at work on [l,r] for (int r = t; r < n - t; r++) { for (int l = t; l <= r; l++) { // in how many meetings can participate int can = remote[l - t] - remote[0] + total[r + 1] - total[l] + remote[n] - remote[r + t + 1]; // remote[0]=total[0]=work[0]=0 if (can >= meetings - skip) { int wm = total[r + 1] - total[l]; int rm = max(0, meetings - skip - wm); mx = max(mx, l - t + n - (r + t + 1) - rm); } } } if (remote[n] >= meetings - skip) { mx = max(mx, n - max(0, meetings - skip)); } if (mx == -inf) mx = -1; cout << mx << '\n'; } signed main() { ios_base::sync_with_stdio(0); int t = 1; //cin >> t; while (t--) solve(); } |
English