This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef Home
#define _GLIBCXX_DEBUG
#endif // Home
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
main() {
#ifdef Home
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // Home
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, k;
cin >> n >> k;
vector < pair < int, int > > AB(n), A(n), B;
for(int i = 0; i < n; ++ i) {
cin >> AB[i].first >> AB[i].second;
A[i] = {AB[i].first, i};
}
sort(A.begin(), A.end());
for(int i = 0; i < n; ++ i) {
if(AB[A[i].second].second != -1) {
B.push_back({AB[A[i].second].second, i});
}
}
sort(B.begin(), B.end());
ld ans = 1e9, tmp, c;
for(int t = 0; t <= (int)B.size(); ++ t) {
if(t == k) {
break;
}
tmp = .0, c = 1;
for(int i = 0; i < t; ++ i) {
tmp += (ld)B[i].first / c;
++ c;
A[B[i].second].first = 0;
}
for(int i = 0, j = k - t; i < n && j; ++ i) {
if(A[i].first) {
-- j;
tmp += A[i].first / c;
}
}
for(int i = 0; i < t; ++ i) {
A[B[i].second].first = AB[A[B[i].second].second].first;
}
ans = min(ans, tmp);
}
cout << fixed << setprecision(2) << ans;
}
Compilation message (stderr)
Main.cpp:12:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
12 | main() {
| ^~~~
# | 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... |