Maximum Sum
Practice
3.7 (175 votes)
Algorithms
Easy
Searching
Problem
89% Success 74618 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

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$$

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
125 votes
Tags:
AlgorithmsEasySearching
Points:30
718 votes
Tags:
ReadyHiringEasy-MediumApprovedSegment tree
Points:20
10 votes
Tags:
MathLinear SearchAlgorithms