#include <bits/stdc++.h>
#define MAX 505
typedef std::pair<double,int> pdd;
typedef std::pair<long long ,long long> pii;
using ll = long long;
double LGD;
int existe[MAX][MAX];
pdd tab[MAX][MAX];
int rodada=52;
int K=0;
std::vector<pii> regs;
int N;
long long C;
double inf = 1LL<<50LL;
pdd dp(int pos,int falta){
if(pos==N&&!falta)return {0.0,0};
if(pos==N){
return {inf,0};
}
if(existe[pos][falta]==rodada)return tab[pos][falta];
existe[pos][falta]=rodada;
double pegou = (K-falta)+1;
pdd ans = {inf,0};
if(falta){
double custo = (double)regs[pos].first/(double)pegou;
pdd g = dp(pos+1,falta-1);
g.first+=custo;
ans=std::min(ans,g);
}
{
if(regs[pos].second<=C){
double custo = (double)regs[pos].second/(double)(K+1);
pdd g = dp(pos+1,falta);
g.first+=custo-((double)C/(double)(K+1));
--g.second;
ans=std::min(ans,g);
}else {pdd g =dp(pos+1,falta);ans=std::min(ans,g);}
}
return tab[pos][falta]=ans;
}
int main()
{
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;
int opt=1e9;
for(K=0;K<=obj;++K){
ll l=0,r=1000;
while(l<r){
ll m = (l+r)/2;
C=m;
++rodada;
auto x = dp(0,K);
if(abs(x.second)>=obj-K){
r=m;
}else l=m+1;
}
assert(l<=opt);
opt=l;
++rodada;
C=l;
auto kek = dp(0,K);
kek.second*=-1;
int quer = obj-K;
kek.first+=(double)kek.second*((double)l/(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*l))/(double)(K+1);
ans=std::min(ans,kek.first);
}
std::cout<<std::fixed<<std::setprecision(20)<<ans<<"\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:71:13: warning: unused variable 'quer' [-Wunused-variable]
71 | int quer = obj-K;
| ^~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
125 ms |
3704 KB |
Output is correct |
6 |
Correct |
691 ms |
4384 KB |
Output is correct |
7 |
Execution timed out |
2549 ms |
5268 KB |
Time limit exceeded |
8 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
125 ms |
3704 KB |
Output is correct |
6 |
Correct |
691 ms |
4384 KB |
Output is correct |
7 |
Execution timed out |
2549 ms |
5268 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
1 ms |
340 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 |
340 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 |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
356 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 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 |
0 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 |
1 ms |
340 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 |
340 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 |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
4 ms |
852 KB |
Output is correct |
42 |
Correct |
4 ms |
852 KB |
Output is correct |
43 |
Correct |
12 ms |
952 KB |
Output is correct |
44 |
Correct |
10 ms |
980 KB |
Output is correct |
45 |
Correct |
29 ms |
992 KB |
Output is correct |
46 |
Correct |
23 ms |
968 KB |
Output is correct |
47 |
Correct |
39 ms |
980 KB |
Output is correct |
48 |
Correct |
39 ms |
1080 KB |
Output is correct |
49 |
Correct |
61 ms |
1012 KB |
Output is correct |
50 |
Correct |
55 ms |
1108 KB |
Output is correct |
51 |
Correct |
74 ms |
1012 KB |
Output is correct |
52 |
Correct |
70 ms |
1036 KB |
Output is correct |
53 |
Correct |
35 ms |
988 KB |
Output is correct |
54 |
Correct |
37 ms |
1000 KB |
Output is correct |
55 |
Correct |
41 ms |
1096 KB |
Output is correct |
56 |
Correct |
37 ms |
1016 KB |
Output is correct |
57 |
Correct |
38 ms |
976 KB |
Output is correct |
58 |
Correct |
40 ms |
976 KB |
Output is correct |
59 |
Correct |
39 ms |
980 KB |
Output is correct |
60 |
Correct |
38 ms |
1012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2598 ms |
5188 KB |
Time limit exceeded |
2 |
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 |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
125 ms |
3704 KB |
Output is correct |
6 |
Correct |
691 ms |
4384 KB |
Output is correct |
7 |
Execution timed out |
2549 ms |
5268 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |