DMPG '15 B4 - Maximum Product

View as PDF

Submit solution


Points:7 (partial)
Time limit:1.0s
Memory limit:64M
Author:

Problem type

Bob is playing a card game with his friends, where each card has a number on it. The goal of the game is to make the largest number possible with the cards in his hand. In order to create this number, Bob must pick a subset of at least one card from all of the cards he has in his hand and multiply them. To add to the difficulty of the game, there are cards with negative numbers. Can you help Bob create the largest possible number with his hand?

Input Specification

The first line will contain an integer N (1\le N \le 30), which will represent the number of cards in Bob's hand.

For the next N lines, line i will contain a single integer c (-5 \le c \le 5), representing the value of the i^{th} card in Bob's hand.

Output Specification

A single integer, the maximum product Bob can make with his cards.

Sample Input 1

5
0
1
2
3
4

Sample Output 1

24

Sample Input 2

5
-2
-3
-4
3
1

Sample Output 2

36

Comments


  • -1
    susheelk
     commented on Nov. 19, 2015, 4:11 p.m.
    Cases 5 and 10

    Any thoughts on why I'm getting 1 for cases 5 and 10?


    • 0
      anishmahto
       commented on June 26, 2016, 11:24 p.m.

      Does your code overlook a scenario with only 0s? What about 0s and 1 negative number? Or what if there is only 1 number, and that is a negative?

      Don't overlook any possible situations, unless specified in the problem statement.


  • 2
    PaulOlteanu
     commented on July 11, 2015, 11:14 p.m.
    Getting some weird (what I assume to be) undefined behaviour

    Occasionally, I get 5625 for test case #4. I assume this has to do with the selection of the judge, but I can't find anything non-standard with my code.


    • 2
      FatalEagle
       commented on July 12, 2015, 9:47 a.m.

      You are sorting short but you are casting them to int* in the comparator.


      • 0
        PaulOlteanu
         commented on July 13, 2015, 6:29 p.m.

        Ahh... Thanks