#include <bits/stdc++.h>
#include <fstream>
using namespace std;
template<class A, class B>
ostream& operator<<(ostream& o, const pair<A, B>& p) {return o << '(' << p.first << ", " << p.second << ')';}
template<size_t Index = 0, typename... Types>
ostream& printTupleElements(ostream& o, const tuple<Types...>& t) {if constexpr (Index < sizeof...(Types)){if(Index > 0){o << ", ";}o << get<Index>(t);printTupleElements<Index + 1>(o, t);}return o;}
template<typename... Types>
ostream& operator<<(ostream& o, const tuple<Types...>& t){o << "(";printTupleElements(o, t);return o << ")";}
template<class T>
auto operator<<(ostream& o, const T& x) -> decltype(x.end(), o){o << '{';bool first = true;for (const auto& e : x){if (!first){o << ", ";}o << e;first = false;} return o << '}';}
#define DEBUG
#ifdef DEBUG
#define fastio()
#define debug(x...) cerr << "[" #x "]: ", [](auto... $) {((cerr << $ << "; "), ...); }(x), cerr << '\n'
#define check(x) if (!(x)) { cerr << "Check failed: " << #x << " in line " << __LINE__ << endl; exit(1); }
#else
#define fastio() ios_base::sync_with_stdio(0); cin.tie(0);
#define debug(...)
#define check(x)
#endif
typedef long long ll;
typedef long double ld;
#define pi pair<int, int>
#define pl pair<ll, ll>
#define st first
#define nd second
#define vi vector<int>
#define vll vector<ll>
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
vector<pair<ld, ld> >prz;
int n, k;
ld cntdp(int x) {
vector<vector<ld> >dp(k + 1, vector<ld>(x + 1, 1e9));
dp[0][0] = 0;
for(int i = 0; i < sz(prz); i++) {
for(int l = min(i + 1, x); l >= 0; l--) {
int j = min(i + 1, k);
if(l > 0) {
dp[j][l] = min(dp[j][l], dp[j - 1][l - 1] + prz[i].st / (ld)l);
}
dp[j][l] = min(dp[j][l], dp[j - 1][l] + prz[i].nd / (ld)(x + 1));
}
}
for(int i = 0; i <= k; i++) {
//debug(i, dp[i]);
}
return dp[k][x];
}
void solve() {
//ifstream cin("nazwa.in");
//ofstream cout("nazwa.out");
cin >> n >> k;
for(int i = 1; i <= n; i++) {
int a, b;
cin >> a >> b;
if(b == -1) {
b = 1e9;
}
prz.eb(b, a);
}
sort(all(prz));
ld ans = 1e9;
for(int i = 0; i <= k; i++) {
ans = min(ans, cntdp(i));
}
cout.precision(9);
cout << fixed << ans << '\n';
}
int main() {
fastio();
int t;
//cin >> t;
t = 1;
while(t--) {
solve();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
43 ms |
912 KB |
Output is correct |
7 |
Correct |
175 ms |
1684 KB |
Output is correct |
8 |
Correct |
423 ms |
2936 KB |
Output is correct |
9 |
Correct |
723 ms |
4868 KB |
Output is correct |
10 |
Correct |
354 ms |
2608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
43 ms |
912 KB |
Output is correct |
7 |
Correct |
175 ms |
1684 KB |
Output is correct |
8 |
Correct |
423 ms |
2936 KB |
Output is correct |
9 |
Correct |
723 ms |
4868 KB |
Output is correct |
10 |
Correct |
354 ms |
2608 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
72 ms |
1036 KB |
Output is correct |
13 |
Incorrect |
64 ms |
1012 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
728 ms |
4752 KB |
Output is correct |
2 |
Correct |
727 ms |
4740 KB |
Output is correct |
3 |
Correct |
734 ms |
4764 KB |
Output is correct |
4 |
Correct |
737 ms |
4780 KB |
Output is correct |
5 |
Correct |
751 ms |
4676 KB |
Output is correct |
6 |
Correct |
715 ms |
4644 KB |
Output is correct |
7 |
Correct |
730 ms |
4680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
604 KB |
Output is correct |
6 |
Correct |
43 ms |
912 KB |
Output is correct |
7 |
Correct |
175 ms |
1684 KB |
Output is correct |
8 |
Correct |
423 ms |
2936 KB |
Output is correct |
9 |
Correct |
723 ms |
4868 KB |
Output is correct |
10 |
Correct |
354 ms |
2608 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
72 ms |
1036 KB |
Output is correct |
13 |
Incorrect |
64 ms |
1012 KB |
Output isn't correct |
14 |
Halted |
0 ms |
0 KB |
- |