eolymp
bolt
Try our new interface for solving problems
Problems

Two biggest

published at 1/26/24, 11:55:57 am

include <iostream>

include <algorithm>

int main() { int n; std::cin >> n;

int* array = new int[n];  // Динамічно виділяємо масив розміром n

for (int i = 0; i < n; ++i) {
    std::cin >> array[i];
}

// Сортуємо масив у порядку спадання
std::sort(array, array + n, std::greater<int>());

// Знаходимо суму двох найбільших елементів
int sum = array[0] + array[1];

std::cout << sum << std::endl;

delete[] array;  // Звільняємо пам'ять, виділену для масиву

return 0;

}