AmazonOA #378
Get Success Value (Fungible :)
Estimated EasyJudge-ready
Topics (AI-labelled)Prefix & RangesIn-place Arrays
For each query k, find the total number of viewers in the k regions with the most viewers. Regions with equal viewer counts are counted separately; queries are independent and are answered in input order.
Input
The first line contains n q, the second line contains n viewer counts, and the third line contains q queries. Original bounds: 1≤n,q≤100000, 1≤viewers≤10^9, 1≤k≤n. This site outputs exact integers, not limited by the original int return signature.
Output
Output q exact integers in query order, separated by whitespace.
Example 1
Input:
3 3
5 6 10
1 2 3
Output:
10 16 21
Example 2
Input:
3 2
7 7 1
2 1
Output:
14 7
Example 3
Input:
1 2
1
1 1
Output:
1 1
Example notes
The outputs of the three public examples are, in order: 10 16 21; 14 7; 1 1. Verified by independent enumeration or direct simulation.
Editorial
Loading solution…