Untitled

 avatar
unknown
c_cpp
2 years ago
945 B
3
Indexable
#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];
}

Editor is loading...
Leave a Comment