Problem:
Problem D:
THE BYDOLM@STER
Description
THE BYDOLM@STER(バイドルマスター)とは1rem社より2010/4/1にEXIDNAで発売が予定されている育成シミュレーションゲームである。一応断っておくが、今月初めにネットワーク接続サービスが停止した某アーケードゲームとはたぶん関係が無い。
このゲームはバイドルたちからプロデュースするユニット(編隊)のメンバーを選択し、メンバーたちとのレッスンやコミュニケーションを通じて、彼女(彼)らをバイドルの頂点、トップバイドルに育て上げるゲームである。
各バイドルには能力値としてボーカル、ダンス、ルックスの3つのパラメータを持ち、ユニットの能力値はユニットに属している全てのバイドルのパラメータの合計値となる。ユニットの3つの能力値のうち最大の物がユニットのランクとなる。
ユニットに人数制限は無く、メンバーの人数が1体でも、3体でも、100体でもユニットとして活動できる。もちろん同じバイドルを複数雇うこと出来るが、バイドルを雇うためには費用がかかるのでこれを考慮に入れなければならない。
プロデューサーであるあなたは最高のユニットを作るためにプログラムを書いて計算することにした。
Input
入力は複数のテストケースからなる。
各テストケースの1行目にはバイドルの数Nと使用可能な費用Mが与えられる。(1<=N,M<=300)
次の2*N行には各バイドルに関しての情報が書かれている。
バイドルの情報の1行目にはバイドルの名前。バイドルの名前はアルファベットと空白から成り、30文字を以下である。また同一名のバイドルは存在しない。
2行目には整数C、V、D、Lが与えられる。Cはそのバイドルを1体雇用するコスト、Vはボーカル、Dはダンス、Lはルックスの能力値を表す。(1<=C,V,D,L<=300)
入力はEOFで終わる。
Output
与えられた費用の中で作れるユニットのランクの最大値を答えよ。
ユニットが作れない場合は0を出力せよ。
Sample Input
3 10
Dobkeradops
7 5 23 10
PataPata
1 1 2 1
dop
5 3 11 14
2 300
Bydo System Alpha
7 11 4 7
Green Inferno
300 300 300 300
Output for Sample Input
29
462

Submitted solutions:

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
int dpru(int *c, int *v) {
  int dp[2][333]; // Reduced the size of the dp array
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[(i + 1)%2][j] = dp[i%2][j]; // Use the current and previous rows only
      if (j >= c[i])
        max_swap(dp[(i + 1)%2][j], dp[(i + 1)%2][j - c[i]] + v[i]); // Use the current and previous rows only
    }
  }
  return dp[n%2][m]; // Return the value from the current row
}
int main() {
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 3088
final_rank: 4

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif

#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)

typedef long long ll;
typedef pair<int, int> pint;

const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int n, m;

int dpru(int *c, int *v) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        dp[i + 1][j] = max(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}

int main() {
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) res = max(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 150
memory_kb: 3536
final_rank: 8

code_snippet: #include <algorithm>
#include <iostream>
#include <cstring>
using namespace std;

const int MAX_N = 333;
const int MAX_M = 333;

int dp[MAX_M];
int n, m;

int dpru(int *c, int *v) {
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[j] = max(dp[j], (j >= c[i] ? dp[j - c[i]] + v[i] : 0));
    }
  }
  return dp[m];
}

int main() {
  while (cin >> n >> m) {
    int c[MAX_N], v[3][MAX_N];
    for (int i = 0; i < n; ++i) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      for (int j = 0; j < 3; ++j) {
        cin >> v[j][i];
      }
    }
    int res = 0;
    for (int i = 0; i < 3; ++i) {
      res = max(res, dpru(c, v[i]));
    }
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 80
memory_kb: 2988
final_rank: 2

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < idols.size(); j++) {
        for (int k = 0; k <= 300; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 280
memory_kb: 3956
final_rank: 16

code_snippet: #include <algorithm>
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }

int dpru(int *c, int *v, int n, int m) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}

int main() {
  int n, m;
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i], n, m));
    cout << res << '\n';
  }
}
accuracy: 1
time_ms: 150
memory_kb: 3640
final_rank: 11

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    int size = idols.size();
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < size; j++) {
        for (int k = 0; k <= 300; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          int valC = dp[i - idols[j].mC * k][0] + idols[j].mV * k;
          int valD = dp[i - idols[j].mC * k][1] + idols[j].mD * k;
          int valL = dp[i - idols[j].mC * k][2] + idols[j].mL * k;
          dp[i][0] = max(valC, dp[i][0]);
          dp[i][1] = max(valD, dp[i][1]);
          dp[i][2] = max(valL, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 250
memory_kb: 3916
final_rank: 14

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    idols.reserve(N);
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int j = 0; j < idols.size(); j++) {
      for (int i = 0; i <= M; i++) {
        for (int k = 0; k <= i/idols[j].mC; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 320
memory_kb: 3944
final_rank: 19

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int j = 0; j < idols.size(); j++) {
      for (int i = 0; i <= M; i++) {
        for (int k = 0; k <= 300; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 260
memory_kb: 3920
final_rank: 15

code_snippet: #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int n, m;

int dpru(int *c, int *v) {
  int dp[333][333];
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i]) {
        int temp = dp[i + 1][j - c[i]] + v[i];
        if (temp > dp[i + 1][j]) {
          dp[i + 1][j] = temp;
        }
      }
    }
  }
  return dp[n][m];
}

int main() {
  while (cin >> n >> m) {
    int c[333], v[999];
    memset(c, 0, sizeof(c));
    memset(v, 0, sizeof(v));
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[i + j * n];
    }
    int res = 0;
    rep(i, 3) {
      int temp = dpru(c, v + i * n);
      if (temp > res) {
        res = temp;
      }
    }
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 160
memory_kb: 3564
final_rank: 9

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < idols.size(); j++) {
        for (int k = 0; k <= M; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 270
memory_kb: 4064
final_rank: 17

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < idols.size(); j++) {
        for (int k = 0; k <= 300; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 280
memory_kb: 4064
final_rank: 18

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
int dpru(int *c, int *v) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}
int main() {
  while (~scanf("%d%d", &n, &m)) {
    int c[333], v[3][333];
    rep(i, n) {
      getchar();
      while (getchar() != '\n')
        ;
      int t;
      scanf("%d", &t);
      c[i] = t;
      rep(j, 3) scanf("%d", v[j] + i);
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    printf("%d\n", res);
  }
}
accuracy: 1
time_ms: 110
memory_kb: 3548
final_rank: 6

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
int dpru(int *c, int *v) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}
int main() {
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 150
memory_kb: 3632
final_rank: 10

code_snippet: #pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
    return (ull)rng() % B;
}
inline double time() {
    return static_cast<long double>(chrono::duration_cast<chrono::nanoseconds>(chrono::steady_clock::now().time_since_epoch()).count()) * 1e-9;
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n,m;
    while (cin >> n >> m) {
        cin.ignore();
        string s;
        vector<int> c(n);
        vector<vector<int>> v(3, vector<int>(n));
        for (int i = 0; i < n; i++) {
            getline(cin, s);
            cin >> c[i] >> v[0][i] >> v[1][i] >> v[2][i];
            cin.ignore();
        }
        int res = 0;
        for (int _ = 0; _ < 3; _++) {
            auto u = v[_];
            vector<int> dp(m+1, 0);
            for (int i = 0; i < n; i++) {
                for (int j = 0; j+c[i] <= m; j++) {
                    dp[j+c[i]] = max(dp[j+c[i]], dp[j]+u[i]);
                }
            }
            res = max(res, dp.back());
        }
        cout << res << endl;
    }
}
accuracy: 1
time_ms: 10
memory_kb: 3480
final_rank: 3

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
const int MAX_N = 300;
const int MAX_M = 300;
int dp[MAX_N + 1][MAX_M + 1][3];
int main() {
  int N, M;
  string line;
  stringstream ss;
  while (getline(cin, line)) {
    ss << line;
    ss >> N >> M;
    ss.clear();
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      ss << line;
      int C, V, D, L;
      ss >> C >> V >> D >> L;
      ss.clear();
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i < N; i++) {
      for (int j = 0; j <= M; j++) {
        for (int k = 0; k <= MAX_N; k++) {
          if (j - idols[i].mC * k < 0)
            break;
          dp[i + 1][j][0] =
              max(dp[i][j - idols[i].mC * k][0] + idols[i].mV * k,
                  dp[i + 1][j][0]);
          dp[i + 1][j][1] =
              max(dp[i][j - idols[i].mC * k][1] + idols[i].mD * k,
                  dp[i + 1][j][1]);
          dp[i + 1][j][2] =
              max(dp[i][j - idols[i].mC * k][2] + idols[i].mL * k,
                  dp[i + 1][j][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[N][i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 330
memory_kb: 5064
final_rank: 20

code_snippet: #define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, P> PP;
int tx[] = {0, 1, 0, -1};
int ty[] = {-1, 0, 1, 0};
static const double EPS = 1e-8;
class Data {
public:
  string mName;
  int mC, mV, mD, mL;
  Data(string _n, int _c, int _v, int _d, int _l) {
    mName = _n;
    mC = _c;
    mV = _v;
    mD = _d;
    mL = _l;
  }
};
int dp[301][3];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int N, M;
  string line;
  while (getline(cin, line)) {
    stringstream ss(line);
    ss >> N >> M;
    vector<Data> idols;
    for (int i = 0; i < N; i++) {
      getline(cin, line);
      string name = line;
      getline(cin, line);
      stringstream ss2(line);
      int C, V, D, L;
      ss2 >> C >> V >> D >> L;
      idols.push_back(Data(name, C, V, D, L));
    }
    memset(dp, 0, sizeof(dp));
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < idols.size(); j++) {
        for (int k = 1; k <= 300; k++) {
          if (i - idols[j].mC * k < 0)
            break;
          dp[i][0] =
              max(dp[i - idols[j].mC * k][0] + idols[j].mV * k, dp[i][0]);
          dp[i][1] =
              max(dp[i - idols[j].mC * k][1] + idols[j].mD * k, dp[i][1]);
          dp[i][2] =
              max(dp[i - idols[j].mC * k][2] + idols[j].mL * k, dp[i][2]);
        }
      }
    }
    int maxv = 0;
    for (int i = 0; i <= M; i++) {
      for (int j = 0; j < 3; j++) {
        maxv = max(dp[i][j], maxv);
      }
    }
    printf("%d\n", maxv);
  }
}
accuracy: 1
time_ms: 240
memory_kb: 3304
final_rank: 13

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int MAXN = 333;
int n, m;
int c[MAXN], v[3][MAXN];
int dp[2][MAXN];
int dpru(int *c, int *v) {
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[1][j] = dp[0][j];
      if (j >= c[i])
        max_swap(dp[1][j], dp[1][j - c[i]] + v[i]);
    }
    swap(dp[0], dp[1]);
  }
  return dp[0][m];
}
int main() {
  while (cin >> n >> m) {
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 120
memory_kb: 3180
final_rank: 5

code_snippet: #include <algorithm>
#include <cstring>
#include <iostream>
using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)

const int MAXN = 333;

int n, m;
int c[MAXN], v[3][MAXN];
int dp[2][MAXN];

void max_swap(int &a, const int &b) { a = max(a, b); }

int dpru(int *c, int *v) {
  memset(dp, 0, sizeof(dp));
  int now = 0, pre = 1;
  for (int i = 0; i < n; ++i) {
    swap(now, pre);
    for (int j = 0; j <= m; ++j) {
      dp[now][j] = dp[pre][j];
      if (j >= c[i])
        max_swap(dp[now][j], dp[now][j - c[i]] + v[i]);
    }
  }
  return dp[now][m];
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> n >> m) {
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
  return 0;
}
accuracy: 1
time_ms: 30
memory_kb: 3224
final_rank: 1

code_snippet: #include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
int dpru(int *c, int *v) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 100
memory_kb: 3636
final_rank: 7

code_snippet: #pragma GCC optimize("O3")
#pragma GCC target("sse4")
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using namespace std;
#ifdef _MSC_VER
#define __typeof__ decltype
template <class T> int __builtin_popcount(T n) {
  return n ? 1 + __builtin_popcount(n & (n - 1)) : 0;
}
#endif
#define foreach(it, c)                                                         \
  for (__typeof__((c).begin()) it = (c).begin(); it != (c).end(); ++it)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define CLEAR(arr, val) memset(arr, val, sizeof(arr))
#define rep(i, n) for (int i = 0; i < n; ++i)
template <class T> void max_swap(T &a, const T &b) { a = max(a, b); }
template <class T> void min_swap(T &a, const T &b) { a = min(a, b); }
typedef long long ll;
typedef pair<int, int> pint;
const double PI = acos(-1.0);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
int n, m;
int dpru(int *c, int *v) {
  int dp[333][333];
  CLEAR(dp, 0);
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j <= m; ++j) {
      dp[i + 1][j] = dp[i][j];
      if (j >= c[i])
        max_swap(dp[i + 1][j], dp[i + 1][j - c[i]] + v[i]);
    }
  }
  return dp[n][m];
}
int main() {
  while (cin >> n >> m) {
    int c[333], v[3][333];
    rep(i, n) {
      string s;
      int t;
      getline(cin, s);
      getline(cin, s);
      cin >> t;
      c[i] = t;
      rep(j, 3) cin >> v[j][i];
    }
    int res = 0;
    rep(i, 3) max_swap(res, dpru(c, v[i]));
    cout << res << endl;
  }
}
accuracy: 1
time_ms: 160
memory_kb: 3596
final_rank: 12