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 <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 ];
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;
}
for ( long long i = 1; i <= n; i ++ )
dp[ 0 ][ i ] = oo;
ans = oo;
sort( a + 1, a + n + 1 );
for ( long long k = 0; k <= m; k ++ ) {
for ( long long i = 1; i <= n; i ++ ) {
for ( long long j = 1; j <= n; j ++ )
dp[ i ][ j ] = oo;
}
for ( long long i = 1; i <= n; i ++ ) {
num = i;
if ( num <= k )
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ] + a[ i ].first / num;
else
dp[ i ][ 0 ] = dp[ i - 1 ][ 0 ];
for ( long long j = 1; j <= min( i, m ); j ++ ) {
num = i - j;
if ( num <= k )
dp[ i ][ j ] = min( dp[ i - 1 ][ j - 1 ] + a[ i ].second / ( k + 1 ), dp[ i - 1 ][ j ] + a[ i ].first / num );
else
dp[ i ][ j ] = min( dp[ i - 1 ][ j - 1 ] + a[ i ].second / ( k + 1 ), dp[ i - 1 ][ j ] );
// cout << k << " " << i << " " << j << " - " << dp[ i ][ j ] << " " << num << "\n";
}
}
// cout << k << " - " << dp[ n ][ m - k ] << "\n";
ans = min( ans, dp[ n ][ m - k ] );
}
cout << fixed << setprecision(4) << ans;
}
Compilation message (stderr)
Main.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
50 | main () {
| ^~~~
# | 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... |