fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios_base::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. long long c;
  8. cin>>c;
  9. string s;
  10. cin>>s;
  11. long long counter=1;
  12. long long sum=0;
  13. bool f=1;
  14. for(int i=0;i<s.size();i++)
  15. {
  16. if(s[i]=='0')
  17. {
  18. f=0;
  19. }
  20. }
  21. if(f)
  22. {
  23. cout<<1;
  24. }
  25. else{
  26. for(int i=0;i<s.size();i++)
  27. {
  28. if(s[i]=='0')
  29. {
  30. if(sum==c)
  31. {
  32. break;
  33. }
  34. counter++;
  35. sum=max(sum,counter);
  36. if(sum==c)
  37. {
  38. break;
  39. }
  40.  
  41. }
  42. if(s[i]=='1'&&counter>1)
  43. {
  44. counter--;
  45. }
  46.  
  47. }
  48. cout<<sum;}
  49. return 0;
  50. }
Success #stdin #stdout 0.01s 5288KB
stdin
2
00
stdout
2