-
Notifications
You must be signed in to change notification settings - Fork 186
Expand file tree
/
Copy pathb.cc
More file actions
36 lines (34 loc) · 669 Bytes
/
b.cc
File metadata and controls
36 lines (34 loc) · 669 Bytes
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
// https://codeforces.com/contest/1315/problem/B
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
cin.tie(0), ios::sync_with_stdio(0);
ll t, a, b, p;
cin >> t;
while (t--) {
cin >> a >> b >> p;
string s;
cin >> s;
int n = s.size();
int k = n, c = s[n-2];
if (c == 'A') p -= a;
else p -= b;
if (p < 0) {
cout << k << '\n';
continue;
}
for (int i = n - 2; i >= 0; i--) {
if (s[i] == c) {
k = i+1;
continue;
}
c = s[i];
if (s[i] == 'A') p -= a;
else p -= b;
if (p < 0) break;
k = i+1;
}
cout << k << '\n';
}
}