Блог пользователя myaw

Автор myaw, история, 9 лет назад, По-английски

The problem look like this : we have n object each object have a weight .

We want to create 2 groups of these objects so the number of objects on the two groups must not differ by more than 1 and the total weight of the objects on each group should be as nearly equal as possible.

examples :

n = 4 : 1 2 3 4 => ans : 5 5

n = 4 : 1 2 3 11111 => ans : 5 11112

n = 3 : 100 90 200 => ans :190 200

my code works fine for small input how ever it gives negative values for large input (n >= 25 ) . My code

You should now that n<=100 and the sum of weights is <= 1e6 .

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

memo array size

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Nothing wrong with memo size , i increased it and still got WA .

    • »
      »
      »
      9 лет назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      you asked how it gives negatives actually, and not how to solve it. But since you still getting WA (todo: since 100002 gives WA anyway, reduce it to 1 element), then array size must be good — that is simple logic, right? Sorry about my suggestion and please ignore my comment + that below in such case.

      "You should now that n<=100 and the sum of weights is <= 1e6" + line 8. ll memo[100002]; 100002 <= 1e6, and sum of weights <= 1e6, .... ?? sum of weights <= 100002 ?? SOLID

»
9 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

Try to make the array memo with bigger size beacause the maximum sum that is possible is 1e8 but yout memo has only 1e6. :D