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;
#ifdef MIKU
const string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif
#define int long long
#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
typedef pair<int, int> pii;
const int MXN = 505;
int n, k;
pii p[MXN];
double calc(int x) {
sort(p, p + n, [](pii a, pii b) -> bool {
// if (a.sc == -1 && b.sc == -1) return a.fs < b.fs;
// if (a.sc == -1) return false;
// if (b.sc == -1) return true;
// return (a.sc == b.sc ? a.fs > b.fs : a.sc < b.sc);
return (a.sc == b.sc ? a.fs < b.fs : a.sc < b.sc);
});
sort(p + x, p + n, [](pii a, pii b) -> bool {
return a.fs < b.fs;
});
double ans = 0.0;
FOR(i, 0, x) ans += (double) p[i].sc / (i + 1);
FOR(i, x, k) ans += (double) p[i].fs / (x + 1);
return ans;
}
void miku() {
cin >> n >> k;
FOR(i, 0, n) {
cin >> p[i].fs >> p[i].sc;
}
int x = count_if(p, p + n, [](pii a) -> bool {
return a.sc != -1;
});
FOR(i, 0, n) p[i].sc = (p[i].sc == -1 ? INT_MAX : p[i].sc);
double ans = 3.9e18;
FOR(i, 0, min(x, k) + 1) {
double y = calc(i);
// debug(x);
ans = min(ans, y);
}
cout << fixed << setprecision(10) << ans << '\n';
}
int32_t main() {
cin.tie(0) -> sync_with_stdio(false);
cin.exceptions(cin.failbit);
miku();
return 0;
}
# | 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... |