5
Time limit5sMemory limit555 MB
Given an array of non-negative integers with sum S and at least S/5 ones, count the pairs (k, T) where some subsequence of length k sums to T.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Math
- Solved
- No attempts yet
Problem
You are given an array of length consisting of non-negative integers. Calculate the number of pairs such that there exists a subsequence of of length whose sum is equal to . Just kidding, this is too general. Suppose the sum of elements of is equal to . Then it is guaranteed that has at least elements equal to .
Input
The first line contains two positive integers and (), the number of elements in and their sum. The second line contains the array (). It is guaranteed that and at least elements of are equal to .
Output
Print the number of pairs such that there exists a subsequence of of length whose sum is equal to .