PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000129. Người mê mua sắm (Shopaholic)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Người mê mua sắm (Shopaholic)
Shopaholic
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
In a buy-three-pay-two promotion the cheapest item of each group of three is free. You must buy all items and may choose their grouping. Find the maximum total discount, not the amount paid.
Input
The first line contains . The next line contains prices .
Output
Print the maximum total discount.
Subtasks
- Subtask 1 (20 points): ; .
- Subtask 2 (30 points): ; .
- Subtask 3 (50 points): ; .
Examples
Input
7
400 350 300 250 200 150 100
Output
450
Explanation
Sorted descending, groups and give free items and , for a saving of .