#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]);
}else if(B[i] == -1){
dp[a][b] = min(dp[a][b],dp[a - 1][b] + (A[i] / ld(b + 1)));
}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))));
}
}
}
}
ld minimum = 1e18;
for(ll j = 0;j <= N;j++){
minimum = min(minimum,dp[K][j]);
}
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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
32 ms |
1316 KB |
Output is correct |
7 |
Correct |
112 ms |
2260 KB |
Output is correct |
8 |
Correct |
158 ms |
3272 KB |
Output is correct |
9 |
Correct |
197 ms |
4252 KB |
Output is correct |
10 |
Correct |
160 ms |
3072 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
32 ms |
1316 KB |
Output is correct |
7 |
Correct |
112 ms |
2260 KB |
Output is correct |
8 |
Correct |
158 ms |
3272 KB |
Output is correct |
9 |
Correct |
197 ms |
4252 KB |
Output is correct |
10 |
Correct |
160 ms |
3072 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
56 ms |
1508 KB |
Output is correct |
13 |
Correct |
47 ms |
1508 KB |
Output is correct |
14 |
Correct |
47 ms |
1512 KB |
Output is correct |
15 |
Correct |
210 ms |
3028 KB |
Output is correct |
16 |
Correct |
170 ms |
3076 KB |
Output is correct |
17 |
Correct |
143 ms |
3076 KB |
Output is correct |
18 |
Correct |
231 ms |
4252 KB |
Output is correct |
19 |
Correct |
202 ms |
4256 KB |
Output is correct |
20 |
Correct |
194 ms |
4256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
1 ms |
320 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
316 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 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 |
305 ms |
4248 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
7 ms |
724 KB |
Output is correct |
6 |
Correct |
32 ms |
1316 KB |
Output is correct |
7 |
Correct |
112 ms |
2260 KB |
Output is correct |
8 |
Correct |
158 ms |
3272 KB |
Output is correct |
9 |
Correct |
197 ms |
4252 KB |
Output is correct |
10 |
Correct |
160 ms |
3072 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
56 ms |
1508 KB |
Output is correct |
13 |
Correct |
47 ms |
1508 KB |
Output is correct |
14 |
Correct |
47 ms |
1512 KB |
Output is correct |
15 |
Correct |
210 ms |
3028 KB |
Output is correct |
16 |
Correct |
170 ms |
3076 KB |
Output is correct |
17 |
Correct |
143 ms |
3076 KB |
Output is correct |
18 |
Correct |
231 ms |
4252 KB |
Output is correct |
19 |
Correct |
202 ms |
4256 KB |
Output is correct |
20 |
Correct |
194 ms |
4256 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
320 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |