СРОЧНО!!! Гвоздики С++
Ответы на вопрос
#include <iostream>
#include <bitset>
#include <vector>
using namespace std;
int main() {
vector<int> nails;
vector<bool> filaments;
int size;
cin >> size;
nails.resize(size);
filaments.resize(size);
for (int i = 0; i < size; ++i) {
cin >> nails[i];
filaments[i] = 0;
}
int sum = 0;
for (int i = 0; i < size; ++i) {
if (filaments[i] == false) {
int min = 10000, indexMin = -1;
for (int j = 0; j < size; ++j)
if (abs(nails[i] - nails[j]) < min && i != j) {
min = nails[i] - nails[j];
indexMin = j;
}
sum += abs(nails[i] - nails[indexMin]);
filaments[i] = 1;
filaments[indexMin] = 1;
}
}
cout << sum;
}