#include #include #include #include using namespace std; int main() { int N; cin >> N; vector sequence(N); for (int i = 0; i < N; ++i) { cin >> sequence[i]; } // Sort the sequence in descending order to handle larger numbers first sort(sequence.rbegin(), sequence.rend()); set uniqueNumbers; int operations = 0; for (int i = 0; i < N; ++i) { while (sequence[i] > 0 && !uniqueNumbers.insert(sequence[i]).second) { // Decrement the number and increase the operation count sequence[i]--; operations++; } } cout << operations << endl; return 0; } /*nput: This code first reads the number of elements and then the sequence itself. It sorts the sequence in descending order to handle larger numbers first, which is a more efficient approach to minimize the number of operations. For each number, if it's already in the set, the program decreases it until it's either zero or a unique number, counting the number of operations performed. Finally, it outputs the total number of operations needed to make the sequence diverse. Example 7 5 1 5 8 8 7 8 Output: 8 Example 6 1 2 3 1 2 3 Output: 6 Example 4 2 0 2 3 Output: 1 6 0 5 0 3 9 0 Output: 0 6 2 5 2 7 3 4 Output: 1 20 49 17 12 6 17 2 34 9 21 31 33 20 30 36 24 21 34 42 1 50 5 55 923 202 216 430 489 662 750 285 874 168 662 939 370 451 619 602 337 712 471 923 944 146 843 368 343 604 279 498 185 390 331 148 986 781 488 740 168 624 616 981 926 482 308 404 779 627 105 673 780 699 126 730 275 884 426 3 */