LKS  Large Knapsack
The knapsack problem or rucksack problem is a problem in combinatorial optimization: Given a set of items, each with a weight and a value, determine the number of each item to include in a collection so that the total weight is less than or equal to a given limit and the total value is as large as possible. It derives its name from the problem faced by someone who is constrained by a fixedsize knapsack and must fill it with the most valuable items.
Just implement 0/1 Knapsack.
Input
First line contains two integers K and N, where K in the maximum knapsack size and N is the number of items. N lines follow where i^{th} line describes i^{th} item in the form v_{i} and w_{i} where v_{i} is the value and w_{i} is the weight of i^{th} item.
Output
Output a single number  maximum value of knapsack. (All operations and the answer are guaranteed to fit in signed 32bit integer.)
Time limit changed to 2s on 02.07.11.
Example
Input: 10 3 7 3 8 8 4 6 Output: 11
Constraints
K <= 2000000
N <= 500
V_{i} <= 10^7
W_{i} <= 10^7
hide comments
nipun_baishnab:
20190815 19:57:32
my fst day of learning knapsack and accepted in one go!!


spartan09:
20190708 13:38:44
use int instead of long long int 

mr_robo1:
20190520 11:31:22
AC in first submission 

itssanat:
20181104 07:03:14
AC in one go :) !!!! 

jeet9:
20180913 22:25:07
Memoized. Got AC in one go ! :D 

luka_dzimba911:
20180220 22:51:19
For all of you wondering how to get 0.0s learn branch and bound algorithm very useful and fun


elliotto:
20180212 23:03:31
*Edit: nevermind, i used a different compiler and it was fine.


akashbhalotia:
20171224 10:16:35
This should help if you stuck for a long time. See the second program in this link : https://www.geeksforgeeks.org/spaceoptimizeddpsolution01knapsackproblem/ 

rohit9934:
20170705 17:59:10
use the optimized knapsack


vivace:
20170615 11:47:42
How are people getting 0.00 seconds on this one . My space optimised 01 knapsack dp of order O(nW) took 1 second even in C. 
Added by:  Shikhar 
Date:  20130624 
Time limit:  2s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ASM64 