QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#442838 | #8524. Weather Forecast | ucup-team3890# | WA | 1ms | 4712kb | C++14 | 1.0kb | 2024-06-15 13:38:22 | 2024-06-15 13:38:23 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+99;
const double eps=1e-8;
int n,k,a[N];
double s[N];
int p[N],pos[N];
bool cmp(int A,int B){
if(fabs(s[A]-s[B])<=eps) return A<B;
return s[A]<s[B];
}
int bit[N];
int query(int x){
int re=0;
while(x){
re=max(re,bit[x]);
x-=(x&(-x));
}
return re;
}
void add(int x,int val){
while(x<N){
bit[x]=max(bit[x],val);
x+=(x&(-x));
}
return;
}
bool judge(double mid){
for(int i=1;i<=n;i++)
s[i]=s[i-1]+a[i]-mid;
for(int i=1;i<=n;i++) p[i]=i;
sort(p+1,p+n+1,cmp);
for(int i=1;i<=n;i++) pos[p[i]]=i;
memset(bit,0,sizeof(bit));
int now;
for(int i=1;i<=n-1;i++){
if(s[i]<0) continue;
now=query(pos[i])+1;
add(i,now);
}
now=query(pos[n])+1;
return now>=k;
}
int main(){
std::ios::sync_with_stdio(false);
cin.tie(0);
cin>>n>>k;
for(int i=1;i<=n;i++)
cin>>a[i];
double l=0,r=1000,mid,ans;
while(r-l>eps){
mid=(l+r)/2;
if(judge(mid)) ans=mid,l=mid;
else r=mid;
}
cout<<fixed<<setprecision(8)<<ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 4712kb
input:
7 3 1 3 1 2 2 2 1
output:
1.66666666
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 4508kb
input:
1 1 1
output:
999.99999999
result:
wrong answer 1st numbers differ - expected: '1.00000', found: '1000.00000', error = '999.00000'