RT,
for(int j=1;j<=n;j++) for(int i=m;i>=0;i--) for(int k=1;k<=cnt;k++) if(w[k]<=i) f[i]=min(f[i-w[k]]-v[k],f[i]);