Magic Potion
Practice
3.8 (11 votes)
Algorithms
Binary search
Easy
Searching
Problem
69% Success 2882 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Shruti loves to play with Array. She would always be busy doing some random operation with her array. Today she got to know about Magic Potion. A Magic Potion is a special power that allows you to remove one element from your array either from the start or the end. After spending some time on Magic Potion she decided to use it on her arrays.

Shruti has an array of size N. She calls an array a Good array if the sum of the array is exactly K. She wants to apply Magic Potion on her array so that she could get a Good array. She wants to find the count of all the Good arrays that could be formed from the given initial array by applying Magic Potion on them any number of times. She is also interested in finding out the minimum Magic Potion required to form a single Good array. Since she is already quite busy she asks you for help.

Input:

The first line contains 2 integers N and K denoting the size of the array and the sum value required for an array to be Good.This is followed by N-space separated integers that denote the array.

Output:

Print two space-separated integers where the first integers denote the count of all possible Good arrays while the second integers indicate minimum Magic Potion required for a Good array.

Constraints:

1 \(\le\) N \(\le\) 105

1 \(\le\) K \(\le\) 1012

0 \(\le\) Ai \(\le\) 109

Note:

A Good Array will always exist.

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:30
8 votes
Tags:
AlgorithmsBinary SearchDepth First SearchDisjoint setEasyGraphsLife-cycle assessmentSearching
Points:30
29 votes
Tags:
C++Basic ProgrammingBit ManipulationBasics of Bit ManipulationAlgorithmsBinary Search
Points:30
55 votes
Tags:
ApprovedBinary SearchEasyGreedy AlgorithmsReadySorting