Choosing Malatang Ingredients
InterviewTime limit1sMemory limit1024 MB
Given an N by N compatibility matrix, find the largest sum of pairwise scores over exactly K chosen ingredients.
- Level
Easy3 of 10
- Topics
- Brute force, Bit manipulation
- Solved
- No attempts yet
Problem
Hayak likes putting several ingredients into malatang. Adding many ingredients does not always make it tastier, though. Each pair of ingredients has a compatibility score, so some combinations taste good together and others do not. Hayak is stuck on this problem.
How can Hayak maximize the flavor of malatang when using exactly ingredients?
Let be the compatibility of ingredient and ingredient when they are put in together. The flavor of the malatang is the sum of the compatibility scores over every pair of ingredients in the pot. If is the chosen group of ingredients, the flavor is:
For Hayak, find the maximum flavor when exactly ingredients are used.
Input
The first line contains two integers () and (), separated by a space. The number of ingredients is , and is the number of ingredients to choose.
The next lines describe the compatibility scores. Line contains the sequence of integers, separated by spaces. () It is given that and .
Output
Print one line with the maximum flavor of malatang when exactly ingredients are used.