QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#442957 | #8524. Weather Forecast | ucup-team3890# | WA | 1ms | 6740kb | C++20 | 1.1kb | 2024-06-15 13:56:17 | 2024-06-15 13:56:18 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+99;
#define double long double
const double eps=1e-10;
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]+(double)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;
if(s[n]<0) return false;
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 6672kb
input:
7 3 1 3 1 2 2 2 1
output:
1.66666667
result:
ok found '1.66667', expected '1.66667', error '0.00000'
Test #2:
score: 0
Accepted
time: 1ms
memory: 4592kb
input:
1 1 1
output:
1.00000000
result:
ok found '1.00000', expected '1.00000', error '0.00000'
Test #3:
score: 0
Accepted
time: 1ms
memory: 4596kb
input:
2 1 2 1
output:
1.50000000
result:
ok found '1.50000', expected '1.50000', error '0.00000'
Test #4:
score: 0
Accepted
time: 0ms
memory: 6740kb
input:
3 2 2 4 4
output:
3.00000000
result:
ok found '3.00000', expected '3.00000', error '0.00000'
Test #5:
score: 0
Accepted
time: 1ms
memory: 6640kb
input:
4 2 6 7 3 12
output:
6.50000000
result:
ok found '6.50000', expected '6.50000', error '0.00000'
Test #6:
score: -100
Wrong Answer
time: 1ms
memory: 4572kb
input:
5 3 17 23 13 12 21
output:
17.20000000
result:
wrong answer 1st numbers differ - expected: '16.50000', found: '17.20000', error = '0.70000'