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;
typedef int64_t ll; typedef pair<int, int> pii;
#define pb emplace_back
#define AI(x) begin(x),end(x)
#define ff first
#define ss second
#ifdef OWO
#define debug(args...) LKJ("\033[0;32m[ " + string(#args) + " ]\033[0m", args)
template<class I> void LKJ(I&&x) { cerr << x << endl; }
template<class I, class...T> void LKJ(I&&x, T&&...t) { cerr << x << ", "; LKJ(t...); }
template<class I> void OI(I a, I b) { while (a < b) cerr << *a << " \n"[next(a) == b]; }
#else
#define debug(...) 0
#define OI(...) 0
#endif
signed main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int N; cin >> N;
int K; cin >> K;
int has_co = 0;
vector<int> A(N + 1), B(N + 1);
for (int i = 1; i <= N; ++i) {
cin >> A[i] >> B[i];
has_co += (B[i] != -1);
if (B[i] == -1) B[i] = 1'000'000'000;
}
vector<int> co(N);
iota(AI(co), 1);
sort(AI(co), [&](int u, int v) {
if (B[u] != B[v])
return B[u] < B[v];
return A[u] > A[v];
});
double ans = 1e18;
for (int c = 0; c <= has_co; ++c) {
double tmp = 0;
for (int i = 0; i < c; ++i)
tmp += B[co[i]] / (double) (i + 1);
vector<int> oth;
for (int i = c; i < N; ++i)
oth.pb(co[i]);
sort(AI(oth), [&](int u, int v) {
return A[u] < A[v];
});
double mul = c + 1;
for (int i = 0; i + c < K; ++i) {
tmp += A[oth[i]] / mul;
if (A[oth[i]] == B[oth[i]])
mul += 1;
}
debug(c, tmp);
ans = min(ans, tmp);
}
cout << setprecision(10) << fixed << ans << '\n';
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:14:20: warning: statement has no effect [-Wunused-value]
14 | #define debug(...) 0
| ^
Main.cpp:56:3: note: in expansion of macro 'debug'
56 | debug(c, tmp);
| ^~~~~
# | 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... |