codefoces 1272D
时间: 2023-08-21 08:05:33 浏览: 97
CodeForces
Sure! Here's a possible solution for Codeforces problem 1272D:
```cpp
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a.begin(), a.end());
int count = 0;
for (int i = 0; i < n - 1; i++) {
if (a[i] == a[i + 1]) {
count++;
a[i + 1]++;
} else if (a[i] > a[i + 1]) {
count += (a[i] - a[i + 1] + 1);
a[i + 1] = a[i] + 1;
}
}
cout << count << endl;
return 0;
}
```
This solution takes an input `n`, followed by `n` integers. It sorts the array and then iterates through it, checking for duplicates or decreasing values. If a duplicate is found, it increments the next element to make them different. If a decreasing value is found, it increments the next element to make it greater than the current one. Finally, it prints the total number of operations performed.
Please note that this is just one possible solution, and there may be other approaches as well.
阅读全文