All Tracks Algorithms Searching Linear Search Problem

Maximum Sum
Tag(s):

Algorithms, Easy, Linear search, Searching algorithm

Problem
Editorial
Analytics

You are given an array of integers $$A$$, you need to find the maximum sum that can be obtained by picking some non-empty subset of the array. If there are many such non-empty subsets, choose the one with the maximum number of elements. Print the maximum sum and the number of elements in the chosen subset.

Input:

The first line contains an integer $$N$$, denoting the number of elements of the array. Next line contains $$N$$ space-separated integers, denoting the elements of the array.

Output:

Print $$2$$ space-separated integers, the maximum sum that can be obtained by choosing some subset and the maximum number of elements among all such subsets which have the same maximum sum.

Constraints:

$$1 \le N \le 10^5$$

$$-10^9 \le A_i \le 10^9$$

SAMPLE INPUT
5
1 2 -4 -2 3
SAMPLE OUTPUT
6 3
Explanation

The chosen subset is {1, 2, 3}.

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

July Easy '18

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?