#pragma GCC optimize("O3,unroll-loop")
#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>;
#define double float
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;
int cnt = 0;
for( auto &i : vc ) if( i.S == -1 ) i.S = INF,++cnt;
cnt = N-cnt+1;
sort( vc.begin()+1, vc.end(), [&]( auto&a, auto&b) {
return a.S < b.S;
});
//V<V<V<double>>> dp( 2, V<V<double>>( K+1, V<double>(K+1, 0) ));
V<V<double>> dp(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 ) */
j = INF;
dp[ 1 ][ 0 ] = 0;
};
auto do_dp = [&](int p) {
double ans=INF;
init();
for( int i = 1; i <= N; ++i ) {
double val = 1.0f*vc[i].F/p;
for( int j = p; j>=1; --j ) {
double val2 = ( j ==1 ? INF :1.0f*vc[i].S/(j-1) );
for( int k = K; k >=1; --k ) {
dp[ j ][ k ] = min({
( j == 1 ? INF : dp[j-1][k-1]+val2 ),
dp[j][k-1] + val,
dp[j][k]
});
}
}
}
//fprintf(stderr, "ans:(%.16lf), p(%d)\n", ans, p );
ans = min( dp[p][K], ans );
return ans;
};
int l = 1, r = cnt;
double ans = INF;
while( r-l > 4 ) {
int l1 = (l+l+r)/3, l2 = (l+r+r)/3;
double ans1 = do_dp(l1);
double ans2 = do_dp(l2);
ans = min( {ans,ans1,ans2} );
if( ans1 > ans2 )
l=l1;
else
r=l2;
}
for( int i = l; i<=r; ++i )
ans = min( ans, do_dp(i));
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();
}
Compilation message
Main.cpp:1:38: warning: bad option '-funroll-loop' to pragma 'optimize' [-Wpragmas]
1 | #pragma GCC optimize("O3,unroll-loop")
| ^
Main.cpp:22:12: warning: bad option '-funroll-loop' to attribute 'optimize' [-Wattributes]
22 | void solve() {
| ^
Main.cpp: In function 'void solve()':
Main.cpp:31:51: warning: bad option '-funroll-loop' to attribute 'optimize' [-Wattributes]
31 | sort( vc.begin()+1, vc.end(), [&]( auto&a, auto&b) {
| ^
Main.cpp:39:18: warning: bad option '-funroll-loop' to attribute 'optimize' [-Wattributes]
39 | auto init = [&]() {
| ^
Main.cpp:45:24: warning: bad option '-funroll-loop' to attribute 'optimize' [-Wattributes]
45 | auto do_dp = [&](int p) {
| ^
Main.cpp: At global scope:
Main.cpp:85:10: warning: bad option '-funroll-loop' to attribute 'optimize' [-Wattributes]
85 | int main() {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
348 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1764 ms |
1444 KB |
Output is correct |
2 |
Correct |
1889 ms |
1444 KB |
Output is correct |
3 |
Correct |
2275 ms |
1436 KB |
Output is correct |
4 |
Correct |
2372 ms |
1444 KB |
Output is correct |
5 |
Execution timed out |
2520 ms |
1368 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
600 KB |
Output is correct |
8 |
Correct |
1 ms |
860 KB |
Output is correct |
9 |
Correct |
1 ms |
1372 KB |
Output is correct |
10 |
Correct |
1 ms |
860 KB |
Output is correct |
11 |
Runtime error |
1 ms |
344 KB |
Execution killed with signal 11 |
12 |
Halted |
0 ms |
0 KB |
- |