#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ull unsigned ll
#define pb push_back
#define epb emplace_back
using namespace std;
const double inf = 1e9 + 1;
int main(){
int n; cin >> n;
int k; cin >> k;
pair<double, double> a[n + 1];
for(int i = 1; i <= n; i++){
cin >> a[i].s >> a[i].f;
if(a[i].f == -1) a[i].f = inf;
}
sort(a + 1, a + 1 + n);
for(int i = 1; i <= n; i++){
//cout << a[i].f << ' ' << a[i].s << "\n";
}
double ans = inf;
for(double x = 0; x <= n; x++){
double dp[n + 1][n + 1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++) dp[i][j] = inf;
}
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= n; j++){
double i1 = i;
double j1 = j;
if(j > 0)dp[i][j] =min(dp[i][j], dp[i - 1][j - 1] + a[i].f / j1);
dp[(int)i][(int)j] = min(dp[i][j], dp[i - 1][j] + a[i].s / (x + 1));
}
}
double cursum = 0;
multiset <pair<double, int> > st;
for(int i = 1; i <= n; i++){
cursum += a[i].s;
st.insert({a[i].s, i});
}
while(st.size() > k) {
cursum -= st.rbegin() -> f;
st.erase(st.find(*st.rbegin()));
}
for(int i = 1; i <= n; i++){
double cur = dp[i - 1][(int)x];
cur += cursum / (x + 1);
if(ans > cur){
//cout << dp[i - 1][x] << "\n";
//cout << x << ' ' << i;
//cout << "\n";
ans = cur;
}
multiset <pair<double, int> > :: iterator it = st.find({a[i].s, i});
if(it != st.end()){
cursum -= a[i].s;
st.erase({a[i].s, i});
}
if(st.size() > k - i && !st.empty()){
cursum -= st.rbegin() -> f;
st.erase(st.find(*st.rbegin()));
}
}
}
cout << fixed << setprecision(7) << ans;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:35:24: warning: unused variable 'i1' [-Wunused-variable]
35 | double i1 = i;
| ^~
Main.cpp:47:25: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
47 | while(st.size() > k) {
| ~~~~~~~~~~^~~
Main.cpp:65:26: warning: comparison of integer expressions of different signedness: 'std::multiset<std::pair<double, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
65 | if(st.size() > k - i && !st.empty()){
| ~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
399 ms |
2280 KB |
Output is correct |
6 |
Correct |
420 ms |
2276 KB |
Output is correct |
7 |
Correct |
451 ms |
2276 KB |
Output is correct |
8 |
Correct |
406 ms |
2280 KB |
Output is correct |
9 |
Correct |
389 ms |
2280 KB |
Output is correct |
10 |
Correct |
388 ms |
2280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
399 ms |
2280 KB |
Output is correct |
6 |
Correct |
420 ms |
2276 KB |
Output is correct |
7 |
Correct |
451 ms |
2276 KB |
Output is correct |
8 |
Correct |
406 ms |
2280 KB |
Output is correct |
9 |
Correct |
389 ms |
2280 KB |
Output is correct |
10 |
Correct |
388 ms |
2280 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
407 ms |
2276 KB |
Output is correct |
13 |
Correct |
396 ms |
2280 KB |
Output is correct |
14 |
Correct |
400 ms |
2276 KB |
Output is correct |
15 |
Correct |
390 ms |
2280 KB |
Output is correct |
16 |
Correct |
418 ms |
2280 KB |
Output is correct |
17 |
Correct |
403 ms |
2280 KB |
Output is correct |
18 |
Correct |
389 ms |
2276 KB |
Output is correct |
19 |
Correct |
392 ms |
2276 KB |
Output is correct |
20 |
Correct |
419 ms |
2276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
300 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
296 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
2 ms |
296 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
417 ms |
2284 KB |
Output is correct |
2 |
Correct |
458 ms |
2308 KB |
Output is correct |
3 |
Correct |
386 ms |
2296 KB |
Output is correct |
4 |
Incorrect |
385 ms |
2380 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
399 ms |
2280 KB |
Output is correct |
6 |
Correct |
420 ms |
2276 KB |
Output is correct |
7 |
Correct |
451 ms |
2276 KB |
Output is correct |
8 |
Correct |
406 ms |
2280 KB |
Output is correct |
9 |
Correct |
389 ms |
2280 KB |
Output is correct |
10 |
Correct |
388 ms |
2280 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
407 ms |
2276 KB |
Output is correct |
13 |
Correct |
396 ms |
2280 KB |
Output is correct |
14 |
Correct |
400 ms |
2276 KB |
Output is correct |
15 |
Correct |
390 ms |
2280 KB |
Output is correct |
16 |
Correct |
418 ms |
2280 KB |
Output is correct |
17 |
Correct |
403 ms |
2280 KB |
Output is correct |
18 |
Correct |
389 ms |
2276 KB |
Output is correct |
19 |
Correct |
392 ms |
2276 KB |
Output is correct |
20 |
Correct |
419 ms |
2276 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
300 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
296 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
2 ms |
296 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Incorrect |
1 ms |
296 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |