KNAPSACK  The Knapsack Problem
The famous knapsack problem. You are packing for a vacation on the sea side and you are going to carry only one bag with capacity S (1 <= S <= 2000). You also have N (1<= N <= 2000) items that you might want to take with you to the sea side. Unfortunately you can not fit all of them in the knapsack so you will have to choose. For each item you are given its size and its value. You want to maximize the total value of all the items you are going to bring. What is this maximum total value?
Input
On the first line you are given S and N. N lines follow with two integers on each line describing one of your items. The first number is the size of the item and the next is the value of the item.
Output
You should output a single integer on one like  the total maximum value from the best choice of items for your trip.
Example
Input: 4 5 1 8 2 4 3 0 2 5 2 3 Output: 13
hide comments
Amanpreet Singh:
20150711 17:26:18
Ac in second attempt. :P


uptoyou:
20150704 10:59:24
AC in one go :)) 

Rishabh Prasad:
20150623 21:32:46
can anyone please the explain the output? 

rohit_dhan:
20150616 14:18:12
First dp... 

nerd:
20150112 18:24:59
my first dp :) 

(Tjandra Satria Gunawan)(æ›¾æ¯…æ˜†):
20150104 20:29:50
Pyramid cluster unavailable for now, all new submission to this problem (and any pyramid problem) rejected :O


Baratheraja R N:
20131206 18:40:41
simliar problem: WACHOVIA


Ouditchya Sinha:
20130312 16:38:30
Great problem for beginners like me... :) 

flareneos:
20111031 06:25:40
You can't take item more than once ? 

.:: Pratik ::.:
20090402 07:32:02
Why are these problems in classical. should they not be in Tutorial mode? 
Added by:  Nikola P Borisov 
Date:  20081110 
Time limit:  0.240s 
Source limit:  50000B 
Memory limit:  1536MB 
Cluster:  Cube (Intel G860) 
Languages:  All except: ERL JSRHINO NODEJS PERL6 VB.NET 