Skip to main content
Back to problems
Codeforces
Easy
Arrays
Sale

Given a list of prices, determine the minimum total cost after applying the usual discount rule to the cheapest item in each selected pair/grouping.

Acceptance 0%
Also Available On
Other platform versions and source mappings for the same problem.
Problem Statement

Sale

You are given prices of items in a shop. The task is to compute the minimum amount of money needed to buy all items when the shop applies a discount rule: among the items considered together, the cheapest one becomes free or gets the required discount according to the problem's sale logic.

For this problem, think of the key idea as identifying the cheapest eligible item(s) after sorting the prices and applying the discount rule to the items that matter. The goal is to produce the final total cost after the sale is applied to the full list.

Intuition

  • Sort prices so the cheapest relevant items are easy to identify.
  • Sum the remaining prices after the discount is applied.
  • This is a straightforward implementation problem with sorting.

Input Format

  • The first line contains an integer nn — the number of items.
  • The second line contains nn integers describing the item prices.

Output Format

  • Print one integer: the final total cost after applying the sale rule.

Constraints

  • 1n1051 \le n \le 10^5
  • Prices are positive integers.
  • The answer fits in a 64-bit signed integer.

Hints

  • Sorting is usually the easiest way to reason about discount-style rules.
  • Check which items are actually discounted and which are fully paid.

Input Format

  • Integer nn.
  • Array of nn item prices.

Output Format

  • A single integer representing the final cost after the sale.

Constraints

  • 1n1051 \le n \le 10^5
  • Prices are positive integers.
  • Use 64-bit arithmetic for the sum.
Examples
Sample cases returned by the problem API.

Example 1

Input

5
5 1 3 4 2

Output

10

Explanation

After arranging the prices, apply the sale rule to the cheapest eligible items and sum the remaining paid prices.

Premium problem context

Unlock deeper context for this problem

Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.