Untitled

mail@pastecode.io avatar
unknown
c_cpp
7 months ago
945 B
0
Indexable
Never
#include <iostream>
#include <vector>
#include <math.h>
int main()
{
    int n{}, i{}, j{}, a{},count_bad = 0;
    int sum {};
    bool swapped{};

    std::vector<int> cost{};
    std::cin >> n;
    
    for (i = 0; i < n; i++) {
        std::cin >> a;
        if (a > 50) {
            cost.push_back(a);
        }
        else {
            sum += a;
            count_bad += 1;
        }
    }
    n -= count_bad;
    for (i = 0; i < n; i++) {
        for (j = 0; j < n - i - 1; j++) {
            swapped = false;
            if (cost[j] > cost[j + 1]) {
                std::swap(cost[j], cost[j + 1]);
                swapped = true;
            }
        }
    }
    for (i = 0; i < n; i++) {
        if (i < n / 2) {
            sum += std::ceil(cost[i] * 0.75);
        }
        else {
            sum += cost[i];
        }
    }
    std::cout << sum << " " << cost[std::floor(n / 2)-1];
}

Leave a Comment