#include #include using namespace std; inline int first_pos(vector &v, int last, int val) { auto b = v.begin(); return distance(b, lower_bound(b, b+last, val)); } int main() { cin.tie(0); ios::sync_with_stdio(false); int N, K; string S; cin >> N >> K; cin >> S; vector buy(55); int carry = 0, b; auto bar = S.cbegin(); buy[0] = 0; for (b = 1; b <= N; b++) { buy[b] = buy[b-1]; int g = 1; while (g--) { buy[b]++; g += (int)(*bar - '0'); if (++bar == S.cend()) { carry = g; goto OUT; } } } OUT:; if (K < N) { cout << first_pos(buy, b, K) << endl; } else if (carry >= b) { cout << b << endl; } else { int rcost = b - carry; cout << b + (K-N)/N*rcost + max(0, first_pos(buy, b, K%N)-carry) << endl; } return 0; }