I was recently solving atcoder dp problems but for Knapsack 1 & Knapsack 2 I'm having a little problem. I saw errichto's stream and saw others code as well but wasn't able to find out where I'm going wrong.
Here is my code for Knapsack-I: https://atcoder.jp/contests/dp/submissions/15549225
And this is for Knapsack-II : https://atcoder.jp/contests/dp/submissions/15548921
Thank you for your time.
You don't consider the first element in your calculations.(which is wrong) Making an array with the size of a non-constant integer is not standard and may cause errors with compilers (it will compile but not work properly). Using some number (100005 for example) or some constant (const int N=1e5; int a[N]; for example)