#include <cstdio>
int main()
{
int h, m, t, mo=0, ms=0;
scanf("%d%d%d", &h, &m, &t);
char d[h+2];
for (int i=0;i<h;i++) {
scanf(" %c", d+i);
if (d[i] == '1') ms++;
else if (d[i] == '2') mo++;
}
if (m > mo+ms) {
m = mo+ms;
}
if (ms <= m) {
printf("%d", h-mo-ms+m);
return 0;
}
int maxx = -1;
for (int b=0; b<h-2*t; b++) {
int hmo = mo;
int hms = ms;
int bmo = 0;
int bms = 0;
for (int i=b;i<b+2*t;i++) {
if (d[i] == '1') hms--;
if (d[i] == '2') hmo--;
}
for (int e = b+2*t; e < h; e++) {
if (d[e-t] == '1') bms++;
if (d[e-t] == '2') bmo++;
if (d[e] == '1') hms--;
if (d[e] == '2') hmo--;
if (ms+mo-hmo-bmo-bms > m) continue;
int matt = hmo + bmo + bms;
int tmo = mo - hmo - bmo;
int tms = ms - hms - bms;
int missed = tmo + tms + hms;
int missable = m - missed;
if (missable > hmo) missable = hmo;
int eval = h - (e - b + 1) - (hmo - missable);
if (eval > maxx) {
maxx = eval;
}
}
}
printf("%d", maxx);
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 | #include <cstdio> int main() { int h, m, t, mo=0, ms=0; scanf("%d%d%d", &h, &m, &t); char d[h+2]; for (int i=0;i<h;i++) { scanf(" %c", d+i); if (d[i] == '1') ms++; else if (d[i] == '2') mo++; } if (m > mo+ms) { m = mo+ms; } if (ms <= m) { printf("%d", h-mo-ms+m); return 0; } int maxx = -1; for (int b=0; b<h-2*t; b++) { int hmo = mo; int hms = ms; int bmo = 0; int bms = 0; for (int i=b;i<b+2*t;i++) { if (d[i] == '1') hms--; if (d[i] == '2') hmo--; } for (int e = b+2*t; e < h; e++) { if (d[e-t] == '1') bms++; if (d[e-t] == '2') bmo++; if (d[e] == '1') hms--; if (d[e] == '2') hmo--; if (ms+mo-hmo-bmo-bms > m) continue; int matt = hmo + bmo + bms; int tmo = mo - hmo - bmo; int tms = ms - hms - bms; int missed = tmo + tms + hms; int missable = m - missed; if (missable > hmo) missable = hmo; int eval = h - (e - b + 1) - (hmo - missable); if (eval > maxx) { maxx = eval; } } } printf("%d", maxx); return 0; } |
English