# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
802945 | acatmeowmeow | Let's Win the Election (JOI22_ho_t3) | C++11 | 5 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, K;
cin >> n >> K;
vector<int> a(n + 5), b(n + 5), index;
for (int i = 1; i <= n; i++) cin >> a[i] >> b[i];
vector<int> arr(a);
sort(arr.begin() + 1, arr.begin() + n + 1);
double ans = 0;
for (int i = 1; i <= K; i++) ans += (double)arr[i];
for (int i = 1; i <= n; i++) if (b[i] != -1) index.push_back(i);
sort(index.begin(), index.end(), [&](int x, int y){ return b[x] < b[y]; });
vector<int> mark(n + 5);
double prefix = 0;
int cnt = 1;
for (auto&i : index) {
mark[i] = true;
prefix += (double)b[i]/cnt;
cnt++;
double res = prefix;
vector<int> rem;
for (int j = 1; j <= n; j++) if (!mark[j]) rem.push_back(j);
sort(rem.begin(), rem.end(), [&](int x, int y) { return a[x] < a[y]; });
for (int j = 0, cur = cnt; j < rem.size() && cur <= K; j++, cur++) res += (double)a[rem[j]]/cnt;
ans = min(ans, res);
}
cout << fixed << setprecision(10) << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |