We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home
  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Constructive Algorithms
  4. Two Subarrays

Two Subarrays

Problem
Submissions
Leaderboard
Discussions
Editorial

Consider an array, , of integers. We define the following terms:

  • Subsequence
    A subsequence of is an array that's derived by removing zero or more elements from without changing the order of the remaining elements. Note that a subsequence may have zero elements, and this is called the empty subsequence.

  • Strictly Increasing Subsequence
    A non-empty subsequence is strictly increasing if every element of the subsequence is larger than the previous element.

  • Subarray
    A subarray of is an array consisting of a contiguous block of 's elements in the inclusive range from index to index . Any subarray of can be denoted by .

The diagram below shows all possible subsequences and subarrays of :

image

We define the following functions:

  • = the maximum sum of some strictly increasing subsequence in subarray

We define the goodness, , of array to be:

In other words, is the maximum possible value of for all possible subarrays of array .

Let be the length of the smallest subarray such that . Given , find the value of as well as the number of subarrays such that and , then print these respective answers as space-separated integers on a single line.

Input Format

The first line contains an integer, , denoting number of elements in array .
The second line contains space-separated integers describing the respective values of .

Constraints

Subtasks

For the of the maximum score:

For the of the maximum score:

Output Format

Print two space-seperated integers describing the respective values of and the number of subarrays satisfying and .

Sample Input 0

3
2 3 1

Sample Output 0

1 1

Explanation 0

The figure below shows how to calculate :

image

is the length of the smallest subarray satisfying . From the table, we can see that . There is only one subarray of length such that .

Author

allllekssssa

Difficulty

Expert

Max Score

70

Submitted By

1437

Need Help?


View discussions
View editorial
View top submissions

rate this challenge

MORE DETAILS

Download problem statement
Download sample test cases
Suggest Edits
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Helpdesk
  • Careers
  • Terms Of Service
  • Privacy Policy

Cookie support is required to access HackerRank

Seems like cookies are disabled on this browser, please enable them to open this website

Join us

Create a HackerRank account

Be part of a 26 million-strong community of developers

Please signup or login in order to view this challenge

or
Already have an account?Log in