My submission gives WA without using cout<<fixed<<setprecision
. Since the median needs atmost 1 decimal place of precision, this feels weird. Any explanations?
Code
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template <class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
template <class X, class Y>
ostream &operator<<(ostream &os, pair<X, Y> const &p)
{
return os << "(" << p.first << ", " << p.second << ") ";
}
template <class Ch, class Tr, class Container>
basic_ostream<Ch, Tr> &operator<<(basic_ostream<Ch, Tr> &os, Container const &x)
{
os << "[ ";
for (auto &y : x)
os << y << ", ";
return os << "]\n";
}
#define int long long
#define len(a) (int)a.size()
const long long INF = 1e18;
const double EPS = 1e-9;
const int di[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dj[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// dp?, graph?, bs on answer?, compress/sort queries?, stupid observation?
int solve_case()
{
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; i++)
cin >> a[i];
double ans = 0;
vector<int> rest;
sort(a.begin(), a.end());
for (int i = 0; i < n; i++)
{
if (i < n - m + 1)
rest.push_back(a[i]);
else
ans += a[i];
}
int k = len(rest);
ans += (rest[(k - 1) / 2] + rest[k / 2]) / 2.0;
cout << ans << '\n';
return 0;
}
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
cout << fixed << setprecision(12);
for (int _ = 1; _ <= t; _++)
{
cout << "Case #" << _ << ": ";
solve_case();
}
return 0;
}