624B.md (1354B)
1 Source: https://codeforces.com/problemset/problem/624/B 2 3 B. Making a String 4 5 time limit per test 6 7 1 second 8 9 memory limit per test 10 11 256 megabytes 12 13 input 14 15 standard input 16 17 output 18 19 standard output 20 21 You are given an alphabet consisting of *n* letters, your task is to make a string of the maximum possible length so that the following conditions are satisfied: 22 23 * the *i*-th letter occurs in the string no more than *a**i* times; 24 * the number of occurrences of each letter in the string must be distinct for all the letters that occurred in the string at least once. 25 26 Input 27 28 The first line of the input contains a single integer *n* (2 ≤ *n* ≤ 26) — the number of letters in the alphabet. 29 30 The next line contains *n* integers *a**i* (1 ≤ *a**i* ≤ 109) — *i*-th of these integers gives the limitation on the number of occurrences of the *i*-th character in the string. 31 32 Output 33 34 Print a single integer — the maximum length of the string that meets all the requirements. 35 36 Examples 37 38 Input 39 40 ``` 41 3 42 2 5 5 43 ``` 44 45 Output 46 47 ``` 48 11 49 ``` 50 51 Input 52 53 ``` 54 3 55 1 1 2 56 ``` 57 58 Output 59 60 ``` 61 3 62 ``` 63 64 Note 65 66 For convenience let's consider an alphabet consisting of three letters: "a", "b", "c". In the first sample, some of the optimal strings are: "cccaabbccbb", "aabcbcbcbcb". In the second sample some of the optimal strings are: "acc", "cbc".