557B - Pasha and Tea - CodeForces Solution


constructive algorithms implementation math sortings *1500

Please click on ads to support us..

Python Code:

n,w=map(int,input().split())
a=sorted(map(int,input().split()))
a1=a[0]
if a[0]*2>a[n]:a1=a[n]/2

if 2*a1*n+a1*n<w:
    print(2*a1*n+a1*n)
else:
    print(w)

C++ Code:

#include <algorithm>
#include <iostream>
#include <vector>

template <typename T>
std::istream& operator >>(std::istream& input, std::vector<T>& v)
{
    for (T& a : v)
        input >> a;

    return input;
}

void answer(double x)
{
    std::cout << std::fixed << x << '\n';
}

void solve(std::vector<unsigned>& a, unsigned w)
{
    const size_t n = a.size() / 2;

    std::sort(a.begin(), a.end());

    const double b = std::min<double>(a[0], a[n] / 2.0);
    answer(std::min<double>(3 * b * n, w));
}

int main()
{
    std::cin.tie(nullptr)->sync_with_stdio(false);

    size_t n;
    std::cin >> n;

    unsigned w;
    std::cin >> w;

    std::vector<unsigned> a(2 * n);
    std::cin >> a;

    solve(a, w);

    return 0;
}


Comments

Submit
0 Comments
More Questions

1364A - XXXXX
1499B - Binary Removals
1569C - Jury Meeting
108A - Palindromic Times
46A - Ball Game
114A - Cifera
776A - A Serial Killer
25B - Phone numbers
1633C - Kill the Monster
1611A - Make Even
1030B - Vasya and Cornfield
1631A - Min Max Swap
1296B - Food Buying
133A - HQ9+
1650D - Twist the Permutation
1209A - Paint the Numbers
1234A - Equalize Prices Again
1613A - Long Comparison
1624B - Make AP
660B - Seating On Bus
405A - Gravity Flip
499B - Lecture
709A - Juicer
1358C - Celex Update
1466B - Last minute enhancements
450B - Jzzhu and Sequences
1582C - Grandma Capa Knits a Scarf
492A - Vanya and Cubes
217A - Ice Skating
270A - Fancy Fence