#include <bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define MAX 505
typedef std::pair<double,int> pdd;
typedef std::pair<long long ,long long> pii;
using ll = long long;
pdd tab[MAX][MAX];
int K=0;
std::vector<pii> regs;
int N;
long long C;
double inf = 1LL<<50LL;
pdd dp(void){
for(int i=0;i!=MAX;++i){
tab[N][i]={inf,0};
}
tab[N][0]={0.0,0};
for(int i=N-1;i!=-1;--i){
for(int j=0;j<=K;++j){
tab[i][j]={inf,0};
const double pegou = K-j+1;
if(j){
double custo = (double)regs[i].first/pegou;
pdd g = tab[i+1][j-1];
g.first+=custo;
tab[i][j]=std::min(tab[i][j],g);
}
if(regs[i].second<=C){
double custo = (double)regs[i].second/(double)(K+1);
pdd g = tab[i+1][j];
g.first+=custo-((double)C/(double)(K+1));
g.second--;
tab[i][j]=std::min(tab[i][j],g);
}else tab[i][j]=std::min(tab[i+1][j],tab[i][j]);
}
}
return tab[0][K];
}
pdd simula(ll kok){
C=kok;
return dp();
}
int main()
{
std::ios::sync_with_stdio(false);
std::cin.tie(0);
std::cout.tie(0);
int obj;
std::cin>>N>>obj;
for(int i=0;i!=N;++i){
ll a,b;
std::cin>>a>>b;
if(b==-1)b=inf;
regs.push_back({b,a});
}
std::sort(regs.begin(),regs.end());
double ans=inf;
ll last=1000;
for(K=0;K<=obj;++K){
while(K!=obj&&last!=1){
auto vec = simula(last-1);
if(abs(vec.second)>=obj-K&&last){
--last;
}else break;
}
auto kek = simula(last);
kek.second*=-1;
kek.first+=(double)kek.second*((double)last/(double)(K+1));
///Pegar quantos a mais selecionei
ll dif = kek.second-(obj-K);
///Descontar os extras (note que eu consigo garantir que o custo eh L)
kek.first-=((double)(dif*last))/(double)(K+1);
ans=std::min(ans,kek.first);
}
std::cout<<std::fixed<<std::setprecision(20)<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
2740 KB |
Output is correct |
6 |
Correct |
73 ms |
3304 KB |
Output is correct |
7 |
Correct |
266 ms |
4176 KB |
Output is correct |
8 |
Correct |
600 ms |
4276 KB |
Output is correct |
9 |
Correct |
1049 ms |
4284 KB |
Output is correct |
10 |
Correct |
341 ms |
4172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
2740 KB |
Output is correct |
6 |
Correct |
73 ms |
3304 KB |
Output is correct |
7 |
Correct |
266 ms |
4176 KB |
Output is correct |
8 |
Correct |
600 ms |
4276 KB |
Output is correct |
9 |
Correct |
1049 ms |
4284 KB |
Output is correct |
10 |
Correct |
341 ms |
4172 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
57 ms |
3492 KB |
Output is correct |
13 |
Correct |
121 ms |
3440 KB |
Output is correct |
14 |
Correct |
135 ms |
3472 KB |
Output is correct |
15 |
Correct |
308 ms |
4284 KB |
Output is correct |
16 |
Correct |
667 ms |
4380 KB |
Output is correct |
17 |
Correct |
743 ms |
4180 KB |
Output is correct |
18 |
Correct |
770 ms |
4288 KB |
Output is correct |
19 |
Correct |
1620 ms |
4284 KB |
Output is correct |
20 |
Correct |
1194 ms |
4284 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
360 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 |
1 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 |
1 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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
360 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 |
1 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 |
1 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 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
420 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
1 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 |
2 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 |
2 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 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
360 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 |
1 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 |
1 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 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
420 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
1 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 |
2 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 |
2 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 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
3 ms |
724 KB |
Output is correct |
42 |
Correct |
2 ms |
724 KB |
Output is correct |
43 |
Correct |
4 ms |
724 KB |
Output is correct |
44 |
Correct |
2 ms |
724 KB |
Output is correct |
45 |
Correct |
7 ms |
724 KB |
Output is correct |
46 |
Correct |
8 ms |
724 KB |
Output is correct |
47 |
Correct |
11 ms |
852 KB |
Output is correct |
48 |
Correct |
8 ms |
852 KB |
Output is correct |
49 |
Correct |
13 ms |
852 KB |
Output is correct |
50 |
Correct |
24 ms |
832 KB |
Output is correct |
51 |
Correct |
41 ms |
888 KB |
Output is correct |
52 |
Correct |
31 ms |
888 KB |
Output is correct |
53 |
Correct |
5 ms |
852 KB |
Output is correct |
54 |
Correct |
5 ms |
852 KB |
Output is correct |
55 |
Correct |
5 ms |
816 KB |
Output is correct |
56 |
Correct |
8 ms |
852 KB |
Output is correct |
57 |
Correct |
5 ms |
852 KB |
Output is correct |
58 |
Correct |
5 ms |
852 KB |
Output is correct |
59 |
Correct |
6 ms |
852 KB |
Output is correct |
60 |
Correct |
6 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1544 ms |
4280 KB |
Output is correct |
2 |
Correct |
1277 ms |
4216 KB |
Output is correct |
3 |
Correct |
1225 ms |
4228 KB |
Output is correct |
4 |
Correct |
1039 ms |
4300 KB |
Output is correct |
5 |
Correct |
823 ms |
4280 KB |
Output is correct |
6 |
Correct |
747 ms |
4280 KB |
Output is correct |
7 |
Correct |
868 ms |
4288 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
17 ms |
2740 KB |
Output is correct |
6 |
Correct |
73 ms |
3304 KB |
Output is correct |
7 |
Correct |
266 ms |
4176 KB |
Output is correct |
8 |
Correct |
600 ms |
4276 KB |
Output is correct |
9 |
Correct |
1049 ms |
4284 KB |
Output is correct |
10 |
Correct |
341 ms |
4172 KB |
Output is correct |
11 |
Correct |
1 ms |
328 KB |
Output is correct |
12 |
Correct |
57 ms |
3492 KB |
Output is correct |
13 |
Correct |
121 ms |
3440 KB |
Output is correct |
14 |
Correct |
135 ms |
3472 KB |
Output is correct |
15 |
Correct |
308 ms |
4284 KB |
Output is correct |
16 |
Correct |
667 ms |
4380 KB |
Output is correct |
17 |
Correct |
743 ms |
4180 KB |
Output is correct |
18 |
Correct |
770 ms |
4288 KB |
Output is correct |
19 |
Correct |
1620 ms |
4284 KB |
Output is correct |
20 |
Correct |
1194 ms |
4284 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
360 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 |
1 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 |
1 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 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
2 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
420 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
2 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
340 KB |
Output is correct |
45 |
Correct |
2 ms |
340 KB |
Output is correct |
46 |
Correct |
3 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
2 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
3 ms |
724 KB |
Output is correct |
62 |
Correct |
2 ms |
724 KB |
Output is correct |
63 |
Correct |
4 ms |
724 KB |
Output is correct |
64 |
Correct |
2 ms |
724 KB |
Output is correct |
65 |
Correct |
7 ms |
724 KB |
Output is correct |
66 |
Correct |
8 ms |
724 KB |
Output is correct |
67 |
Correct |
11 ms |
852 KB |
Output is correct |
68 |
Correct |
8 ms |
852 KB |
Output is correct |
69 |
Correct |
13 ms |
852 KB |
Output is correct |
70 |
Correct |
24 ms |
832 KB |
Output is correct |
71 |
Correct |
41 ms |
888 KB |
Output is correct |
72 |
Correct |
31 ms |
888 KB |
Output is correct |
73 |
Correct |
5 ms |
852 KB |
Output is correct |
74 |
Correct |
5 ms |
852 KB |
Output is correct |
75 |
Correct |
5 ms |
816 KB |
Output is correct |
76 |
Correct |
8 ms |
852 KB |
Output is correct |
77 |
Correct |
5 ms |
852 KB |
Output is correct |
78 |
Correct |
5 ms |
852 KB |
Output is correct |
79 |
Correct |
6 ms |
852 KB |
Output is correct |
80 |
Correct |
6 ms |
852 KB |
Output is correct |
81 |
Correct |
1544 ms |
4280 KB |
Output is correct |
82 |
Correct |
1277 ms |
4216 KB |
Output is correct |
83 |
Correct |
1225 ms |
4228 KB |
Output is correct |
84 |
Correct |
1039 ms |
4300 KB |
Output is correct |
85 |
Correct |
823 ms |
4280 KB |
Output is correct |
86 |
Correct |
747 ms |
4280 KB |
Output is correct |
87 |
Correct |
868 ms |
4288 KB |
Output is correct |
88 |
Correct |
15 ms |
2756 KB |
Output is correct |
89 |
Correct |
10 ms |
2644 KB |
Output is correct |
90 |
Correct |
70 ms |
3204 KB |
Output is correct |
91 |
Correct |
45 ms |
3352 KB |
Output is correct |
92 |
Correct |
305 ms |
4188 KB |
Output is correct |
93 |
Correct |
182 ms |
4408 KB |
Output is correct |
94 |
Correct |
612 ms |
4280 KB |
Output is correct |
95 |
Correct |
441 ms |
4324 KB |
Output is correct |
96 |
Correct |
1116 ms |
4380 KB |
Output is correct |
97 |
Correct |
715 ms |
4280 KB |
Output is correct |
98 |
Correct |
365 ms |
4296 KB |
Output is correct |
99 |
Correct |
334 ms |
4172 KB |
Output is correct |
100 |
Correct |
293 ms |
4284 KB |
Output is correct |
101 |
Correct |
363 ms |
4284 KB |
Output is correct |
102 |
Correct |
372 ms |
4196 KB |
Output is correct |
103 |
Correct |
365 ms |
4364 KB |
Output is correct |
104 |
Correct |
380 ms |
4284 KB |
Output is correct |
105 |
Correct |
192 ms |
4288 KB |
Output is correct |