/* [NWERC'09] Mountain Road by: Jan Kuipers */ #include #include #include using namespace std; typedef vector VI; typedef vector VVI; typedef vector VVVI; int main () { int runs; cin>>runs; while (runs--) { int N; cin>>N; VVI t(2),dt(2); VI T(2,0); for (int i=0; i>c>>_t>>_dt; t[c-'A'].push_back(_t); dt[c-'A'].push_back(_dt); T[c-'A']++; } VVVI best(T[0]+1, VVI(T[1]+1, VI(2, INT_MAX/2))); best[0][0][0]=best[0][0][1]=0; VI n(2); for (n[0]=0; n[0]<=T[0]; n[0]++) for (n[1]=0; n[1]<=T[1]; n[1]++) for (int x=0; x<2; x++) if (n[x]