#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mkp make_pair
#define PH push
#define PB push_back
#define REP(i,N) for( int i = 0; i < (N); ++i )
#define FOR(i,a,b) for( int i = (a); i <= (b); ++i )
#define ALL(x) begin(x), end(x)
#define MEM(x) memset(x, 0, sizeof(x))
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T>
using V=vector<T>;
void solve() {
int N, K; cin >> N >> K;
V<pll> vc(N+1);
const ll INF = 1e18;
FOR(i,1,N) cin >> vc[i].F >> vc[i].S;
for( auto &i : vc ) if( i.S == -1 ) i.S = INF;
sort( vc.begin()+1, vc.end(), [&]( auto&a, auto&b) {
return a.S < b.S;
});
V<V<V<double>>> dp( N+1, V<V<double>>( K+1, V<double>(K+1, 0) ));
//double dp[ N+1 ][ K+1 ][ K+1 ];
auto init = [&]() {
for( auto &i : dp ) for( auto &j : i ) for( auto &k : j )
k = INF;
dp[ 0 ][ 1 ][ 0 ] = 0;
};
double ans=INF;
for( int p = 1; p <= 1; ++p ) {
init();
for( int i = 1; i <= N; ++i ) {
for( int j = 1; j <= 1; ++j ) {
for( int k = 1; k <= K; ++k ) {
if( j == 1 )
dp[i][j][k] = min(
dp[i-1][j][k-1] + (1.0*vc[i].F/p),
dp[i-1][j][k]
);
/*
else
dp[ i ][ j ][ k ] = min({
dp[i-1][j-1][k-1]+(1.0*vc[i].S/(j-1)),
dp[i-1][j][k-1] + (1.0*vc[i].F/p),
dp[i-1][j][k]
});
*/
}
}
}
//fprintf(stderr, "ans:(%.16lf), p(%d)\n", ans, p );
ans = min( dp[N][p][K], ans );
}
cout << fixed << setprecision(10);
cout << ans << '\n';
}
int main() {
int T = 1;
#ifdef LOCAL
freopen( "input.txt", "r", stdin);
freopen( "output.txt", "w", stdout );
cin >> T;
#else
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif
while(T--) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
1 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 |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
467 ms |
994644 KB |
Output isn't correct |
2 |
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 |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |