#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int double
#define sqrt sqrtl
using namespace std;
const long long oo = 1e9;
double sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
freopen ( "sum.in", "r", stdin )
*/
long long n, m;
pair<int, int> a[ 501 ];
int dp[ 501 ][ 501 ][ 501 ];
bool cmp( pair<int, int> a, pair<int, int> b ) {
return ( a.first - a.second ) < ( b.first - b.second );
}
main () {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for ( long long i = 1; i <= n; i ++ ) {
cin >> a[ i ].second >> a[ i ].first;
if ( a[ i ].first == -1 )
a[ i ].first = oo;
}
ans = oo;
sort( a + 1, a + n + 1, cmp );
for ( long long t = 0; t <= n; t ++ ) {
for ( long long i = 0; i <= n; i ++ )
for ( long long j = 0; j <= n; j ++ )
dp[ t ][ i ][ j ] = oo;
dp[ t ][ 0 ][ 0 ] = 0;
}
for ( long long k = 0; k <= m; k ++ ) {
for ( long long i = 1; i <= n; i ++ ) {
for ( long long j = 1; j <= min( i, m ); j ++ ) {
if ( j <= k )
dp[ i ][ j ][ j ] = min( dp[ i - 1 ][ j ][ j ], dp[ i - 1 ][ j - 1 ][ j - 1 ] + a[ i ].first / j );
else
dp[ i ][ j ][ k ] = min( dp[ i - 1 ][ j ][ k ], dp[ i - 1 ][ j - 1 ][ k ] + a[ i ].second / ( k + 1 ) );
// if ( k == 4 )
// cout << i << " " << j << " - " << dp[ i ][ j ][ min( j, k ) ] << "\n";
}
}
// cout << k << " - " << dp[ n ][ m ][ k ] << "\n";
ans = min( ans, dp[ n ][ m ][ k ] );
}
cout << fixed << setprecision( 4 ) << ans;
}
Compilation message
Main.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
53 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
470 ms |
984564 KB |
Output is correct |
6 |
Correct |
510 ms |
984564 KB |
Output is correct |
7 |
Correct |
666 ms |
984664 KB |
Output is correct |
8 |
Correct |
1000 ms |
984680 KB |
Output is correct |
9 |
Correct |
1314 ms |
984564 KB |
Output is correct |
10 |
Correct |
990 ms |
984548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
470 ms |
984564 KB |
Output is correct |
6 |
Correct |
510 ms |
984564 KB |
Output is correct |
7 |
Correct |
666 ms |
984664 KB |
Output is correct |
8 |
Correct |
1000 ms |
984680 KB |
Output is correct |
9 |
Correct |
1314 ms |
984564 KB |
Output is correct |
10 |
Correct |
990 ms |
984548 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
542 ms |
984576 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Incorrect |
1 ms |
580 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Incorrect |
1 ms |
580 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
588 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Incorrect |
1 ms |
580 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1195 ms |
984676 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
470 ms |
984564 KB |
Output is correct |
6 |
Correct |
510 ms |
984564 KB |
Output is correct |
7 |
Correct |
666 ms |
984664 KB |
Output is correct |
8 |
Correct |
1000 ms |
984680 KB |
Output is correct |
9 |
Correct |
1314 ms |
984564 KB |
Output is correct |
10 |
Correct |
990 ms |
984548 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Incorrect |
542 ms |
984576 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |