#FT0000054. Tính trung bình MK trên luồng số (Finding MK Average)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Tính trung bình MK trên luồng số (Finding MK Average)
Finding MK Average
Source: LeetCode
Version: Phuoc Hung OJ Extended
Problem Statement
A stream of positive integers starts empty. Fixed parameters and define MKAverage: if the stream has fewer than elements, it is -1. Otherwise, take the most recent elements, sort them, discard the smallest and largest elements (counting duplicates individually), and floor the arithmetic mean of the remaining elements.
Process operation 1 x to append and operation 2 to print the current MKAverage. Only the most recent elements are used in any calculation.
Input
- Line 1: integers for the window length, discarded count per end and number of operations.
- Next lines: either
1 xto append or2to query MKAverage, with no second parameter for type2.
Output
For every type 2 query, print one integer: -1 before the stream reaches length , otherwise its MKAverage.
Subtasks
Subtask 1 (20 points):
- ; and ; ; type
1 xhas ; each operation is type1or2.
Subtask 2 (30 points):
- ; and ; ; type
1 xhas ; each operation is type1or2.
Subtask 3 (50 points):
- ; and ; ; type
1 xhas ; each operation is type1or2.
Examples
Examples 1
Input
3 1 9
1 3
1 1
2
1 10
2
1 5
1 5
1 5
2
Output
-1
3
5
Explanation
With only 3 and 1 inserted, the first query outputs -1. Adding 10 yields the sorted window ; dropping 1 and 10 leaves 3. After appending three 5s, the last three elements are ; discarding one from either end leaves 5.
Examples 2
Input
5 1 7
1 7
1 2
1 9
1 3
1 4
2
2
Output
4
4
Explanation
Sort the five appended values to . Remove 2 and 9, leaving ; . No append occurs between the last two queries, so both return 4.