#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
bool cmp(pair<int,int> a , pair<int,int> b){
if(a.vs == -1)return 0;
if(b.vs == -1)return 1;
if(a.vs != b.vs)return a.vs < b.vs;
return a.vf < b.vf;
}
const int N = 503;
int pre[N][N];
vector<pair<int,int>> v;
double dp[N][N];
int n , k;
double find(int x){
if(x == 0)return pre[0][k-1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++)dp[i][j] = 1e9;
}
dp[0][0] = 0.0;
double res = 1e9;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(i,x); j++){
if(v[i-1].vs == -1){
goto h;
}
if(j == 0){
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
continue;
}
if(j == x){
int rem = k - i;
res = min(res , dp[i-1][j-1] + (double)v[i-1].vs/(double)j + (rem > 0 ? (double)pre[i][rem-1]/(double)(x+1) : 0));
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
}
else {
dp[i][j] = min(dp[i-1][j-1] + (double)v[i-1].vs/(double)j , dp[i-1][j] + (double)v[i-1].vf/(double)(x+1));
}
}
}
h:
return res;
}
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i = 0; i < n; i++){
int x , y;
cin >> x >> y;
v.pb(mp(x,y));
if(y != -1)cnt++;
}
sort(all(v), cmp);
vector<int> tp;
for(int i = n - 1; i >= 0; i--){
tp.pb(v[i].vf);
sv(tp);
int cur = 0 , sum = 0;
for(int j = i; j < n; j++){
sum += tp[cur];
pre[i][cur] = sum;
cur++;
}
}
int l = 1 , r = min(k , cnt);
if(cnt == 0){
cout << pre[0][k-1] << '\n';
return;
}
double ans = 1e9;
while(l <= r){
int mid = (l + r)/2;
double x = find(mid) , y = find(mid - 1);
ans = min(ans , min(x , y));
//cout << mid << ' ' << x << ' ' << y << '\n';
if(x > y){
r = mid - 2;
}
else l = mid + 1;
}
cout << setprecision(10) << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1228 KB |
Output is correct |
9 |
Correct |
4 ms |
1224 KB |
Output is correct |
10 |
Correct |
1 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1228 KB |
Output is correct |
9 |
Correct |
4 ms |
1224 KB |
Output is correct |
10 |
Correct |
1 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
11 ms |
3292 KB |
Output is correct |
13 |
Correct |
7 ms |
3284 KB |
Output is correct |
14 |
Correct |
6 ms |
3284 KB |
Output is correct |
15 |
Correct |
14 ms |
3288 KB |
Output is correct |
16 |
Correct |
8 ms |
3292 KB |
Output is correct |
17 |
Correct |
6 ms |
3284 KB |
Output is correct |
18 |
Correct |
14 ms |
3296 KB |
Output is correct |
19 |
Correct |
9 ms |
3284 KB |
Output is correct |
20 |
Correct |
6 ms |
3284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
17 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
3236 KB |
Output is correct |
2 |
Correct |
14 ms |
3284 KB |
Output is correct |
3 |
Correct |
13 ms |
3296 KB |
Output is correct |
4 |
Correct |
14 ms |
3284 KB |
Output is correct |
5 |
Correct |
15 ms |
3296 KB |
Output is correct |
6 |
Correct |
10 ms |
3296 KB |
Output is correct |
7 |
Correct |
13 ms |
3292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
224 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1236 KB |
Output is correct |
7 |
Correct |
4 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1228 KB |
Output is correct |
9 |
Correct |
4 ms |
1224 KB |
Output is correct |
10 |
Correct |
1 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
11 ms |
3292 KB |
Output is correct |
13 |
Correct |
7 ms |
3284 KB |
Output is correct |
14 |
Correct |
6 ms |
3284 KB |
Output is correct |
15 |
Correct |
14 ms |
3288 KB |
Output is correct |
16 |
Correct |
8 ms |
3292 KB |
Output is correct |
17 |
Correct |
6 ms |
3284 KB |
Output is correct |
18 |
Correct |
14 ms |
3296 KB |
Output is correct |
19 |
Correct |
9 ms |
3284 KB |
Output is correct |
20 |
Correct |
6 ms |
3284 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
37 |
Halted |
0 ms |
0 KB |
- |