#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) (__builtin_popcountll(a))
#define bithigh(a) (63-__builtin_clzll(a))
#define lg bithigh
#define highpow(a) (1LL << (ll)lg(a))
using namespace std;
const ll LINF = 4e18;
const int mxN = 5e2+10, INF = 2e9;
int n, m;
array<int, 2> a[mxN];
ld dp[2][mxN][mxN];
ld Div(ld x, ld y){ return x/y; }
void Solve(){
cin >> n >> m;
for (int i = 1; i <= n; i++){
cin >> a[i][1] >> a[i][0];
if (!~a[i][0]) a[i][0] = INF;
}
sort(a+1, a+n+1);
for (int i = 1; i <= n; i++){
swap(a[i][0], a[i][1]);
if (a[i][1] == INF) a[i][1] = -1;
}
for (int j = 0; j <= n; j++)
for (int t = 0; t <= n; t++)
dp[0][j][t] = INF;
dp[0][0][0] = 0;
for (int i = 1; i <= n; i++){
for (int j = 0; j <= n; j++){
for (int t = 0; t <= n; t++){
dp[1][j][t] = dp[0][j][t];
if (j) smin(dp[1][j][t], dp[0][j-1][t] + Div(a[i][0], t+1));
if (~a[i][1] && j && t) smin(dp[1][j][t], dp[0][j-1][t-1] + Div(a[i][1], t));
}
}
for (int j = 0; j <= n; j++)
for (int t = 0; t <= n; t++)
dp[0][j][t] = dp[1][j][t];
}
ld ans = dp[0][m][0];
for (int i = 1; i <= m; i++)
smin(ans, dp[0][m][i]);
cout << ans << en;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0); cerr.tie(0);
cout << setprecision(12) << fixed;
cerr << setprecision(12) << fixed;
cerr << "Started!" << endl;
int t = 1;
//cin >> t;
while (t--)
Solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1198 ms |
8316 KB |
Output is correct |
6 |
Correct |
1350 ms |
8312 KB |
Output is correct |
7 |
Correct |
1171 ms |
8316 KB |
Output is correct |
8 |
Correct |
1299 ms |
8312 KB |
Output is correct |
9 |
Correct |
1145 ms |
8316 KB |
Output is correct |
10 |
Correct |
1324 ms |
8320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1198 ms |
8316 KB |
Output is correct |
6 |
Correct |
1350 ms |
8312 KB |
Output is correct |
7 |
Correct |
1171 ms |
8316 KB |
Output is correct |
8 |
Correct |
1299 ms |
8312 KB |
Output is correct |
9 |
Correct |
1145 ms |
8316 KB |
Output is correct |
10 |
Correct |
1324 ms |
8320 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1868 ms |
8316 KB |
Output is correct |
13 |
Correct |
1658 ms |
8316 KB |
Output is correct |
14 |
Correct |
1318 ms |
8316 KB |
Output is correct |
15 |
Correct |
1724 ms |
8324 KB |
Output is correct |
16 |
Correct |
1542 ms |
8316 KB |
Output is correct |
17 |
Correct |
1279 ms |
8316 KB |
Output is correct |
18 |
Correct |
1776 ms |
8320 KB |
Output is correct |
19 |
Correct |
1576 ms |
8316 KB |
Output is correct |
20 |
Correct |
1393 ms |
8316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1845 ms |
8316 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1198 ms |
8316 KB |
Output is correct |
6 |
Correct |
1350 ms |
8312 KB |
Output is correct |
7 |
Correct |
1171 ms |
8316 KB |
Output is correct |
8 |
Correct |
1299 ms |
8312 KB |
Output is correct |
9 |
Correct |
1145 ms |
8316 KB |
Output is correct |
10 |
Correct |
1324 ms |
8320 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1868 ms |
8316 KB |
Output is correct |
13 |
Correct |
1658 ms |
8316 KB |
Output is correct |
14 |
Correct |
1318 ms |
8316 KB |
Output is correct |
15 |
Correct |
1724 ms |
8324 KB |
Output is correct |
16 |
Correct |
1542 ms |
8316 KB |
Output is correct |
17 |
Correct |
1279 ms |
8316 KB |
Output is correct |
18 |
Correct |
1776 ms |
8320 KB |
Output is correct |
19 |
Correct |
1576 ms |
8316 KB |
Output is correct |
20 |
Correct |
1393 ms |
8316 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Incorrect |
0 ms |
340 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |