Under construction

Still being built. Things may change

Alien Invader Yooni

Interview

Time limit1sMemory limit1024 MB

Summary
Given building heights, each day every tallest building drops by 1; find the total number of lasers fired over D days.
Level

Medium5 of 10

Topics
Sorting, Greedy, Simulation
Solved
No attempts yet

Problem

Yooni, an alien, invades Ulsan, the central city of the world, to conquer the Earth. There are NN buildings in a row in Ulsan, and the height of the ii-th building from the left is hih_i.

Yooni has a plan to destroy Ulsan. Every day, Yooni rides a UFO over the city and fires a laser at the tallest building. A building hit by the laser becomes 1 shorter. If several buildings are tied for the tallest height that day, Yooni fires a laser at every one of them. If all buildings have already reached height 00, Yooni stops firing lasers.

Yooni has followed the plan faithfully for DD days so far. Find the total number of lasers Yooni fired during those DD days.

Input

The first line contains the number of buildings NN and the number of days DD that Yooni carried out the plan, separated by a space. (1≤N≤300 0001\le N\le 300\ 000, 1≤D≤300 0001\le D\le 300\ 000)

The second line contains NN integers hih_i, the heights of the buildings, separated by spaces. (1≤hi≤300 0001\le h_i\le 300\ 000)

Output

Print the total number of lasers Yooni fired during the DD days. (Note that the answer may exceed the 32-bit integer range.)

Examples2

  1. Example 1

    Input
    5 3
    1 3 2 5 4
    
    Expected output
    6
    
  2. Example 2

    Input
    5 2
    1 1 1 1 1
    
    Expected output
    5