knapsack problem

my O( long n) solution giving TLE @dpraveen
http://www.codechef.com/viewsolution/4143667