背包模板
#include<bits/stdc++.h>
using namespace std;
#define fst first
#define sec second
#define sci(num) scanf("%d",&num)
#define scl(num) scanf("%lld",&num)
#define mem(a,b) memset(a,b,sizeof a)
#define cpy(a,b) memcopy(a,b,sizeof b)
typedef long long LL;
typedef pair<int,int> P;
const int MAX_N = 510;
const int MAX_M = 10000010;
bool dp[MAX_M];
int vals[60],cnt;
char s[1000];
int main() {
double mt;
int M,N;
while (~scanf("%lf%d",&mt,&N)) {
M = mt * 100;
if (N == 0) break;
int mx = 0;
mem(dp,0);
cnt = 0;
dp[0] = true;
for (int i =0 ;i < N;i++) {
int c2;
sci(c2);
int sum = 0;
int loc = 0;
bool flag = true;
int tempa = 0,tempb = 0,tempc = 0;
for (int j = 0;j < c2;j++) {
double t;
int num;
scanf("%s",s);
sscanf(s + 2,"%lf",&t);
num = 100 * t;
sum += num;
if (s[0] != 'A' && s[0] != 'B' && s[0] != 'C') {
flag = false;
}
if (s[0] == 'A') tempa += num;
if (s[0] == 'B') tempb += num;
if (s[0] == 'C') tempc += num;
}
if (sum > 100000) flag = false;
if (tempa > 60000) flag = false;
if (tempb > 60000) flag = false;
if (tempc > 60000) flag = false;
if (flag) {
vals[cnt++] = sum;
}
}
for (int i = 0;i < cnt;i++) {
for (int j = M;j >= vals[i];j--) {
if (dp[j - vals[i]]) dp[j] = true;
}
}
for (int j = M;j >= 0;j--) {
if (dp[j]) {
mx = j;
break;
}
}
printf("%.2lf\n",(double) mx /100);
}
}