2015
02-21

# Ahui Writes Word

We all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length of each word does not exceed 10 by only lowercase letters), Ahui wrote the complexity of the total is less than or equal to C.
Question: the maximum value Ahui can get.
Note: input words will not be the same.

The first line of each test case are two integer N , C, representing the number of Ahui’s words and the total complexity of written words. (1 ≤ N ≤ 100000, 1 ≤ C ≤ 10000)
Each of the next N line are a string and two integer, representing the word, the value(Vi ) and the complexity(Ci ). (0 ≤ Vi , Ci ≤ 10)

The first line of each test case are two integer N , C, representing the number of Ahui’s words and the total complexity of written words. (1 ≤ N ≤ 100000, 1 ≤ C ≤ 10000)
Each of the next N line are a string and two integer, representing the word, the value(Vi ) and the complexity(Ci ). (0 ≤ Vi , Ci ≤ 10)

5 20
go 5 8
think 3 7
big 7 4
write 3 5

15
Hint
Input data is huge,please use “scanf(“%s”,s)”


## Ahui Writes Word

Time Limit: 1000ms
Memory Limit: 32768KB

This problem will be judged on HDU. Original ID: 3732
64-bit integer IO format: %I64d      Java class name: Main

We all know that English is very important, so Ahui strive for this in order to learn more English words. To know that word has its value and complexity of writing (the length of each word does not exceed 10 by only lowercase letters), Ahui wrote the complexity of the total is less than or equal to C.
Question: the maximum value Ahui can get.
Note: input words will not be the same.

### Input

The first line of each test case are two integer N , C, representing the number of Ahui’s words and the total complexity of written words. (1 ≤ N ≤ 100000, 1 ≤ C ≤ 10000)
Each of the next N line are a string and two integer, representing the word, the value(Vi ) and the complexity(Ci ). (0 ≤ Vi , Ci ≤ 10)

### Output

Output the maximum value in a single line for each test case.

### Sample Input

5 20
go 5 8
think 3 7
big 7 4
write 3 5

### Sample Output

15
Hint

Input data is huge,please use “scanf(“%s”,s)”

### Source

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <queue>
#include <cstdlib>
#include <string>
#include <set>
#include <stack>
#define LL long long
#define pii pair<int,int>
#define INF 0x3f3f3f3f
using namespace std;
int mp[12][12],dp[10010],a[20],n,m;
int main() {
char s[30];
int u,v,tot;
while(~scanf("%d %d",&n,&m)){
memset(mp,0,sizeof(mp));
for(int i = 0; i < n; i++){
scanf("%s %d %d",s,&u,&v);
mp[u][v]++;
}
memset(dp,0,sizeof(dp));
for(u = 0; u < 11; u++){
for(v = 0; v < 11; v++){
if(mp[u][v]){
int t = log2(mp[u][v]);
for(int k = 0; k <= t; k++){
if(k == t) a[k] = mp[u][v] - (1<<k) + 1;
else a[k] = 1<<k;
}
for(int k = 0; k <= t; k++){
for(int z = m; z >= a[k]*v; z--){
dp[z] = max(dp[z],dp[z-a[k]*v]+u*a[k]);
}
}
}
}
}
printf("%d\n",dp[m]);
}
return 0;
}