Loading Similar Posts
QUESTION1)
#include <bits/stdc++.h>
using namespace std;
void remover(vector<int> &arr, int idx) {
int left = max(0, idx - 1);
int right = min((int)arr.size() - 1, idx + 1);
arr.erase(arr.begin() + left, arr.begin() + right + 1);
}
int main() {
int n;
cin >> n;
vector<int> arr(n);
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
int totalSum = 0;
while (arr.size() > 1) {
int minElement = *min_element(arr.begin(), arr.end());
int minIndex = min_element(arr.begin(), arr.end()) - arr.begin();
totalSum += minElement;
remover(arr, minIndex);
}
cout << totalSum << endl;
return 0;
}