yadv's blog

By yadv, history, 4 years ago, In English

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.

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
4 years ago, # |
  Vote: I like it +4 Vote: I do not like it

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)