input:backpack.in output:backpack.out

Time Limits: 1000 ms Memory Limits: 262144 KB

Description

Input

Output

Sample Input

1
2
3
4
5
6
7
8
9
10
Sample 1:
2 15
3 2
5 3

Sample 2:
3 70
71 100
69 1
1 2

Sample Output

1
2
3
4
5
Sample 1:
10

Sample 2:
140

Data Constraint

Code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include<bits/stdc++.h>
#define IL inline
using namespace std;
typedef long long LL;
const int N=100;
const int M=1e6;
int n;
LL m,w[103];
LL f[M+3];
IL bool eql(LL w1,LL v1,LL w2,LL v2){
return v1*w2==v2*w1;

}
IL bool betr(LL w1,LL v1,LL w2,LL v2){
return v1*w2>v2*w1;

}
int main(){
freopen("backpack.in","r",stdin);
freopen("backpack.out","w",stdout);
scanf("%d%lld",&n,&m);
memset(w,0,sizeof w);
for(int i=1;i<=n;i++){
LL x,y;
scanf("%lld%lld",&x,&y);
w[x]=max(w[x],y);
}
LL tw=1,tv=w[1];
for(LL i=2;i<=N;i++)
if(betr(i,w[i],tw,tv)||(eql(i,w[i],tw,tv)&&i<tw)){
tw=i;
tv=w[i];
}
LL cnt=m/tw-100;
m-=cnt*tw;
LL tmp=tv*cnt;
memset(f,0,sizeof f);
for(LL i=1;i<=N;i++)
for(LL j=i;j<=m;j++)
f[j]=max(f[j],f[j-i]+w[i]);
printf("%lld",tmp+f[m]);
return 0;
}