#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <numeric>
#include <stack>
using namespace std;
using ll = long long int;
#define debug(x) cout << #x << " = " << x << endl;
void solve()
{
int n, k, t;
cin >> n >> k >> t;
string dzien;
cin >> dzien;
vector<int>v1(n + 1, 0);
vector<int>v2(n + 1, 0);
vector<int>v3(n + 1, 0);
vector<int>v12(n + 1, 0);
for (int i = 1; i <= n; i++)//o jeden w prawo
{
v1[i] = v1[i - 1] + (dzien[i - 1] == '1' ? 1 : 0);//biuro
v2[i] = v2[i - 1] + (dzien[i - 1] == '2' ? 1 : 0);//online
v3[i] = v3[i - 1] + (dzien[i - 1] == '3' ? 1 : 0);//wolne
v12[i] = v1[i] + v2[i];//spotkania
}
if (v1[n] <= k)//nie warto wcale jechac
{
cout << min(n,v3[n] + k)<<"\n";
return;
}
int odp = -1;
for (int wyjazd = 0; wyjazd <= n - t; wyjazd++)
{
for (int powrot = wyjazd + t; powrot <= n - t; powrot++)//+1 bo bez sensu inaczej
{
int kk = k;
int ileskipwpodwozy = v12[wyjazd + t] - v12[wyjazd] + v12[powrot + t] - v12[powrot];
int ileskipwdomu = v1[n] - v1[powrot+t] + v1[wyjazd];
kk -= (ileskipwpodwozy+ileskipwdomu);
//praca w biurze nic nie daje
if (kk >= 0)
{
//policz wolne w domu
int ilewolnychwdomu= v3[n] - v3[powrot+t] + v3[wyjazd];
odp = max(odp, kk + ilewolnychwdomu);
}
}
}
cout << odp << "\n";
}
int main()
{
ios::sync_with_stdio(false);
//int t;
//cin >> t;
//while (t--)
//{
solve();
//}
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 65 66 67 | #define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <algorithm> #include <vector> #include <cmath> #include <map> #include <queue> #include <set> #include <numeric> #include <stack> using namespace std; using ll = long long int; #define debug(x) cout << #x << " = " << x << endl; void solve() { int n, k, t; cin >> n >> k >> t; string dzien; cin >> dzien; vector<int>v1(n + 1, 0); vector<int>v2(n + 1, 0); vector<int>v3(n + 1, 0); vector<int>v12(n + 1, 0); for (int i = 1; i <= n; i++)//o jeden w prawo { v1[i] = v1[i - 1] + (dzien[i - 1] == '1' ? 1 : 0);//biuro v2[i] = v2[i - 1] + (dzien[i - 1] == '2' ? 1 : 0);//online v3[i] = v3[i - 1] + (dzien[i - 1] == '3' ? 1 : 0);//wolne v12[i] = v1[i] + v2[i];//spotkania } if (v1[n] <= k)//nie warto wcale jechac { cout << min(n,v3[n] + k)<<"\n"; return; } int odp = -1; for (int wyjazd = 0; wyjazd <= n - t; wyjazd++) { for (int powrot = wyjazd + t; powrot <= n - t; powrot++)//+1 bo bez sensu inaczej { int kk = k; int ileskipwpodwozy = v12[wyjazd + t] - v12[wyjazd] + v12[powrot + t] - v12[powrot]; int ileskipwdomu = v1[n] - v1[powrot+t] + v1[wyjazd]; kk -= (ileskipwpodwozy+ileskipwdomu); //praca w biurze nic nie daje if (kk >= 0) { //policz wolne w domu int ilewolnychwdomu= v3[n] - v3[powrot+t] + v3[wyjazd]; odp = max(odp, kk + ilewolnychwdomu); } } } cout << odp << "\n"; } int main() { ios::sync_with_stdio(false); //int t; //cin >> t; //while (t--) //{ solve(); //} return 0; } |
English