#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC target("avx,avx2,fma")
#define sz(x) int((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using ld = long double; // or double, if TL is tight
using str = string;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
int main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<ii> V(n);
for(int i = 0; i < n; ++i) {
cin >> V[i].first >> V[i].second;
if(V[i].second == -1) V[i].second = 1e9;
}
sort(all(V), [&](auto a, auto b) {
if(a.second != b.second) return a.second < b.second;
return a < b;
});
vi A(n), B(n);
for(int i = 0; i < n; ++i) {
A[i] = V[i].first;
B[i] = V[i].second;
}
const ld INF = 1e18;
vector<vector<ld> > DP(n, vector<ld>(k + 1, INF));
ld re = INF;
for(int nr = 0; nr <= k; ++nr) { /// cati b aleg
for(int i = 0; i < n; ++i)
for(int j = 0; j <= k; ++j) DP[i][j] = INF;
///DP[i][j] : 0...i alegand j A-uri
ld fact = 1. / ld(nr + 1);
DP[0][0] = B[0];
DP[0][1] = A[0] * fact;
for(int i = 0; i + 1 < n; ++i) {
for(int j = 0; j <= min(i + 1, k - nr); ++j) {
int curB = i + 1 - j;
if(curB >= nr) {
DP[i + 1][j] = min(DP[i + 1][j], DP[i][j]); /// nu aleg nimic
}
///aleg A
if(j + 1 <= k)
DP[i + 1][j + 1] = min(DP[i + 1][j + 1], DP[i][j] + A[i + 1] * fact);
///aleg B
if(curB < nr) {
DP[i + 1][j] = min(DP[i + 1][j], DP[i][j] + ld(B[i + 1]) / ld(curB + 1));
}
}
}
re = min(re, DP[n - 1][k - nr]);
}
cout << fixed << setprecision(10) << re << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
14 ms |
860 KB |
Output is correct |
6 |
Correct |
73 ms |
1456 KB |
Output is correct |
7 |
Correct |
269 ms |
2432 KB |
Output is correct |
8 |
Correct |
573 ms |
3416 KB |
Output is correct |
9 |
Correct |
1000 ms |
4392 KB |
Output is correct |
10 |
Correct |
516 ms |
3224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
14 ms |
860 KB |
Output is correct |
6 |
Correct |
73 ms |
1456 KB |
Output is correct |
7 |
Correct |
269 ms |
2432 KB |
Output is correct |
8 |
Correct |
573 ms |
3416 KB |
Output is correct |
9 |
Correct |
1000 ms |
4392 KB |
Output is correct |
10 |
Correct |
516 ms |
3224 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
104 ms |
1648 KB |
Output is correct |
13 |
Correct |
108 ms |
1648 KB |
Output is correct |
14 |
Correct |
102 ms |
1644 KB |
Output is correct |
15 |
Correct |
510 ms |
3216 KB |
Output is correct |
16 |
Correct |
514 ms |
3216 KB |
Output is correct |
17 |
Correct |
518 ms |
3224 KB |
Output is correct |
18 |
Correct |
977 ms |
4392 KB |
Output is correct |
19 |
Correct |
973 ms |
4392 KB |
Output is correct |
20 |
Correct |
1010 ms |
4388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
987 ms |
4388 KB |
Output is correct |
2 |
Correct |
985 ms |
4392 KB |
Output is correct |
3 |
Correct |
976 ms |
4392 KB |
Output is correct |
4 |
Correct |
969 ms |
4396 KB |
Output is correct |
5 |
Correct |
1006 ms |
4388 KB |
Output is correct |
6 |
Correct |
994 ms |
4388 KB |
Output is correct |
7 |
Correct |
988 ms |
4184 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
14 ms |
860 KB |
Output is correct |
6 |
Correct |
73 ms |
1456 KB |
Output is correct |
7 |
Correct |
269 ms |
2432 KB |
Output is correct |
8 |
Correct |
573 ms |
3416 KB |
Output is correct |
9 |
Correct |
1000 ms |
4392 KB |
Output is correct |
10 |
Correct |
516 ms |
3224 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
104 ms |
1648 KB |
Output is correct |
13 |
Correct |
108 ms |
1648 KB |
Output is correct |
14 |
Correct |
102 ms |
1644 KB |
Output is correct |
15 |
Correct |
510 ms |
3216 KB |
Output is correct |
16 |
Correct |
514 ms |
3216 KB |
Output is correct |
17 |
Correct |
518 ms |
3224 KB |
Output is correct |
18 |
Correct |
977 ms |
4392 KB |
Output is correct |
19 |
Correct |
973 ms |
4392 KB |
Output is correct |
20 |
Correct |
1010 ms |
4388 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |