ContinuousKnapsack(w[1..n],v[1..n],L)
//Input:n件物品的重量数组w和价值数组v,背包承重L
//Output:没见物品放入背包的重量数组p[1..n],总价值C
for i=1 to n do
p[i]=0
r[i]=v[i]/w[i]
Sort r in decreasing order,change the order v and w correspondingly
l=0;
k=1
while L>l and k<=n do
if w[k]<=L-1
p[k]=w[k]
l+=w[k]
C+=v[k]
k++
else
p[k]=L-1
l+=p[k]
C+=p[k]*r[k]
return p and C
该算法的时间效率为Θ(nlogn)