#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int, int>
#define pii pair<int, pair<int, int> >
#define fi first
#define se second
int n,k;
pair<long double, long double> A[300005];
bool cmp(pair<long double, long double> a, pair<long double, long double> b){
return a.se < b.se;
}
vector<long double> v;
vector<pair<long double, long double> > v2;
long double dp[105][105][105];
void solve(){
cin >> n >> k;
for(int i=1;i<=n;i++){
long double x, y; cin >> x >> y;
if(y == -1)v.push_back(x);
else v2.push_back({x, y});
}
sort(v2.begin(), v2.end(), cmp);
for(int i=1;i<=v2.size();i++)A[i] = v2[i-1];
for(int i=0;i<v.size();i++)A[i+v2.size()+1] = {v[i], -1};
for(int i=1;i<=k;i++){
for(int j=0;j<=n;j++){
dp[0][i][j] = 1e18;
if(j)dp[0][0][j] = 1e18;
}
}
dp[0][0][0] = 0.0;
for(int i=1;i<=n;i++){
for(int j=0;j<=k;j++){
long double bruh = 1e18;
for(int x=0;x<=n;x++){
dp[i][j][x] = dp[i-1][j][x];
if(j && x && A[i].se > 0)dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x-1] + A[i].se/x);
if(j)dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x] + A[i].fi/(x+1));
bruh = min(bruh, dp[i][j][x]);
}
}
}
long double ans = 1e18;
for(int i=0;i<=n;i++)ans= min(ans, dp[n][k][i]);
cout << fixed << setprecision(12) << ans;
}
main(){
ios::sync_with_stdio(0);cin.tie(0);
int t = 1;
//cin >> t;
while(t--){
solve();
}
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:24:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long double, long double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i=1;i<=v2.size();i++)A[i] = v2[i-1];
| ~^~~~~~~~~~~
Main.cpp:25:15: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for(int i=0;i<v.size();i++)A[i+v2.size()+1] = {v[i], -1};
| ~^~~~~~~~~
Main.cpp: At global scope:
Main.cpp:49:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
49 | main(){
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
75 ms |
30944 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
75 ms |
30944 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 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 |
Runtime error |
646 ms |
56260 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Runtime error |
75 ms |
30944 KB |
Execution killed with signal 11 |
6 |
Halted |
0 ms |
0 KB |
- |