# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
703929 | niter | Let's Win the Election (JOI22_ho_t3) | C++14 | 142 ms | 1356 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<stdio.h>
#include<algorithm>
#define R register int
#define D double
#define I inline
#define INF 999999999
I void Min(D&x,const D y){
if(x>y){
x=y;
}
}
struct State{
int ValA,ValB;
I void Read(){
scanf("%d%d",&ValA,&ValB);
if(ValB==-1){
ValB=INF;
}
}
I friend bool operator<(State A,State B){
return A.ValB<B.ValB;
}
}s[501];
D f[501],g[501];
int suf[502][501];
int main(){
int n,m;
scanf("%d %d",&n,&m);
for(R i=1;i<=n;i++){
s[i].Read();
}
std::sort(s+1,s+n+1);
for(R i=n;i!=0;i--){
for(R j=n-i+1;j!=0;j--){
suf[i][j]=suf[i+1][j-1]+s[i].ValA;
}
for(R j=1;j<=n-i;j++){
if(suf[i+1][j]<suf[i][j]){
suf[i][j]=suf[i+1][j];
}
}
}
D ans=suf[1][m];
for(R i=1;i<=m;i++){
D inv=1/(1.0+i);
f[0]=0;
for(R j=1;j<=n&&j<=m;j++){
for(R k=0;k<=j&&k<=i;k++){
g[k]=INF;
}
for(R k=0;k!=j&&k<=i;k++){
Min(g[k],f[k]+inv*s[j].ValA);
Min(g[k+1],f[k]+s[j].ValB/(1.0+k));
}
for(R k=0;k<=j&&k<=i;k++){
f[k]=g[k];
}
if(j>=i){
Min(ans,f[i]+inv*suf[j+1][m-j]);
}
}
}
printf("%.9lf",ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |