Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int dp[26][1501];
- void solve(int tc) {
- memset(dp, -1, sizeof(dp));
- int N, Q;
- string S;
- cin >> N >> S >> Q;
- while(Q--) {
- int amount; cin >> amount;
- int storeAmount = amount;
- char C; cin >> C;
- if(dp[C - 'a'][amount] != -1) {
- cout << dp[C - 'a'][amount] << nl;
- continue;
- }
- int right = 0, left = 0;
- int mx = 0;
- while(right < N) {
- if(S[right] == C) {
- right++;
- }else if(S[right] != C && amount > 0) {
- right++;
- amount--;
- }else {
- if(S[left] != C) {
- amount++;
- }
- left++;
- }
- mx = max(mx, right - left);
- }
- cout << min(N, mx) << nl;
- dp[C - 'a'][storeAmount] = mx;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement