#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(int 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++){
if(j > 0)dp[i][j] =min(dp[i][j], dp[i - 1][j - 1] + a[i].f / j);
dp[i][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][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:45: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]
45 | while(st.size() > k) {
| ~~~~~~~~~~^~~
Main.cpp:63: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]
63 | if(st.size() > k - i && !st.empty()){
| ~~~~~~~~~~^~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
355 ms |
2276 KB |
Output is correct |
6 |
Correct |
352 ms |
2272 KB |
Output is correct |
7 |
Correct |
345 ms |
2260 KB |
Output is correct |
8 |
Correct |
387 ms |
2380 KB |
Output is correct |
9 |
Correct |
364 ms |
2276 KB |
Output is correct |
10 |
Correct |
347 ms |
2276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
355 ms |
2276 KB |
Output is correct |
6 |
Correct |
352 ms |
2272 KB |
Output is correct |
7 |
Correct |
345 ms |
2260 KB |
Output is correct |
8 |
Correct |
387 ms |
2380 KB |
Output is correct |
9 |
Correct |
364 ms |
2276 KB |
Output is correct |
10 |
Correct |
347 ms |
2276 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
415 ms |
2280 KB |
Output is correct |
13 |
Correct |
417 ms |
2276 KB |
Output is correct |
14 |
Correct |
341 ms |
2380 KB |
Output is correct |
15 |
Correct |
336 ms |
2276 KB |
Output is correct |
16 |
Correct |
338 ms |
2272 KB |
Output is correct |
17 |
Correct |
347 ms |
2272 KB |
Output is correct |
18 |
Correct |
333 ms |
2272 KB |
Output is correct |
19 |
Correct |
388 ms |
2272 KB |
Output is correct |
20 |
Correct |
353 ms |
2268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 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 |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
379 ms |
2276 KB |
Output is correct |
2 |
Correct |
387 ms |
2276 KB |
Output is correct |
3 |
Correct |
476 ms |
2280 KB |
Output is correct |
4 |
Incorrect |
398 ms |
2272 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
355 ms |
2276 KB |
Output is correct |
6 |
Correct |
352 ms |
2272 KB |
Output is correct |
7 |
Correct |
345 ms |
2260 KB |
Output is correct |
8 |
Correct |
387 ms |
2380 KB |
Output is correct |
9 |
Correct |
364 ms |
2276 KB |
Output is correct |
10 |
Correct |
347 ms |
2276 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
415 ms |
2280 KB |
Output is correct |
13 |
Correct |
417 ms |
2276 KB |
Output is correct |
14 |
Correct |
341 ms |
2380 KB |
Output is correct |
15 |
Correct |
336 ms |
2276 KB |
Output is correct |
16 |
Correct |
338 ms |
2272 KB |
Output is correct |
17 |
Correct |
347 ms |
2272 KB |
Output is correct |
18 |
Correct |
333 ms |
2272 KB |
Output is correct |
19 |
Correct |
388 ms |
2272 KB |
Output is correct |
20 |
Correct |
353 ms |
2268 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |