// I cannot understand why WA # include <iostream> # include <cstdio> # include <cstring> using namespace std; # define MAXN 5000000 int Q; int N; int prices [35]; int m; int n; char type; double price; int F [MAXN]; int main () {double q; while (cin> q) {memset (F, 0, sizeof (F); cin> N; if (N = 0) break; Q = (int) (q * 100 ); n = 0; for (int I = 1; I <= N; I ++) {cin> m; int sum = 0; int ma, mb, mc; ma = mb = mc = 0; char bd; Bool flag = true; for (int j = 1; j <= m; j ++) {cin> type> bd> price; if (type! = 'A' & type! = 'B' & type! = 'C') {flag = false; break;} if (type = 'A') {if (ma + price * 100 <= 60000) ma + = price * 100; else {flag = false; break ;}} if (type = 'B') {if (mb + price * 100 <= 60000) mb + = price * 100; else {flag = false; break ;}} if (type = 'C') {if (mc + price * 100 <= 60000) mc + = price * 100; else {flag = false; break ;}} sum = ma + mb + mc; if (sum <= 100000 & flag = true) {n ++; prices [n] = sum ;}} for (int I = 1; I <= n; I ++) {for (int j = Q; j> = prices [I]; j --) {F [j] = max (F [j], F [j-prices [I] + prices [I]) ;}} double ans = (double) (F [Q])/100.00; printf ("%. 2lf \ n ", ans);} return 0 ;}