#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define MAXN (300005)
int main() {
ios_base::sync_with_stdio(false);cin.tie(0);
ll N,K;
cin>>N>>K;
pair<ll,ll> arr[N];
for(ll i = 0;i < N;i++){
cin>>arr[i].second>>arr[i].first;
if(arr[i].first == -1) arr[i].first = 1e18;
}
sort(arr,arr + N);
ld A[N], B[N];
for(ll i = 0;i < N;i++){
A[i] = arr[i].second;
B[i] = arr[i].first;
if(arr[i].first == 1e18){
arr[i].first = -1;
B[i] = -1;
}
}
ld dp[K + 1][N + 1]; //number of A fufilled, number of collaborators (excluding Rie herself)
for(ll i = 0;i <= K;i++){
for(ll j = 0;j <= N;j++){
dp[i][j] = 1e18;
}
}
dp[0][0] = 0;
for(ll i = 0;i < N;i++){
for(ll a = min(K,i + 1);a >= 0;a--){
for(ll b = a;b >= 0;b--){
if(a == 0){
dp[a][b] = 0;
}else if(b == 0){
dp[a][b] = min(dp[a][b],dp[a - 1][b] + A[i]);
dp[a][b] = round(dp[a][b] * 1000) / 1000;
}else if(B[i] == -1){
dp[a][b] = min(dp[a][b],dp[a - 1][b] + (A[i] / ld(b + 1)));
dp[a][b] = round(dp[a][b] * 1000) / 1000;
}else{
dp[a][b] = min(dp[a][b],min(dp[a - 1][b] + (A[i] / ld(b + 1)),
dp[a - 1][b - 1] + (B[i] / ld(b))));
dp[a][b] = round(dp[a][b] * 1000) / 1000;
}
}
}
}
ld minimum = 1e9;
for(ll j = 0;j <= N;j++){
minimum = min(minimum,dp[K][j]);
}
cout<<fixed<<setprecision(9);
cout<<minimum<<'\n';
}
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
740 KB |
Output is correct |
6 |
Correct |
77 ms |
1236 KB |
Output is correct |
7 |
Correct |
246 ms |
2260 KB |
Output is correct |
8 |
Correct |
427 ms |
3284 KB |
Output is correct |
9 |
Correct |
494 ms |
4248 KB |
Output is correct |
10 |
Correct |
388 ms |
3080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
740 KB |
Output is correct |
6 |
Correct |
77 ms |
1236 KB |
Output is correct |
7 |
Correct |
246 ms |
2260 KB |
Output is correct |
8 |
Correct |
427 ms |
3284 KB |
Output is correct |
9 |
Correct |
494 ms |
4248 KB |
Output is correct |
10 |
Correct |
388 ms |
3080 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
123 ms |
1500 KB |
Output is correct |
13 |
Correct |
125 ms |
1492 KB |
Output is correct |
14 |
Correct |
121 ms |
1496 KB |
Output is correct |
15 |
Correct |
417 ms |
3148 KB |
Output is correct |
16 |
Correct |
463 ms |
3068 KB |
Output is correct |
17 |
Correct |
397 ms |
3072 KB |
Output is correct |
18 |
Correct |
551 ms |
4244 KB |
Output is correct |
19 |
Correct |
592 ms |
4304 KB |
Output is correct |
20 |
Correct |
519 ms |
4248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
652 ms |
4244 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
15 ms |
740 KB |
Output is correct |
6 |
Correct |
77 ms |
1236 KB |
Output is correct |
7 |
Correct |
246 ms |
2260 KB |
Output is correct |
8 |
Correct |
427 ms |
3284 KB |
Output is correct |
9 |
Correct |
494 ms |
4248 KB |
Output is correct |
10 |
Correct |
388 ms |
3080 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
123 ms |
1500 KB |
Output is correct |
13 |
Correct |
125 ms |
1492 KB |
Output is correct |
14 |
Correct |
121 ms |
1496 KB |
Output is correct |
15 |
Correct |
417 ms |
3148 KB |
Output is correct |
16 |
Correct |
463 ms |
3068 KB |
Output is correct |
17 |
Correct |
397 ms |
3072 KB |
Output is correct |
18 |
Correct |
551 ms |
4244 KB |
Output is correct |
19 |
Correct |
592 ms |
4304 KB |
Output is correct |
20 |
Correct |
519 ms |
4248 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |