3 solutions
-
1
和老钟方法一样
#include<bits/stdc++.h> using namespace std; int n,L; double ans,i[100005],p[100005],j[100005],k[100005]; int main() { scanf("%d%d",&n,&L); double l=0,r=2000,jin=1e-6,mid; for(int c=0;c<n;c++) scanf("%lf",&i[c]); while(r-l>jin){ mid=(l+r)/2; for(int c=0;c<n;c++){ p[c]=i[c]-mid; if(c){ k[c]=max(k[c-1]+p[c],p[c]); j[c]=j[c-1]+p[c]; }else{ j[c]=k[c]=p[c]; } } ans=j[L-1]; for(int c=L;c<n;c++){ double ans1=j[c]-j[c-L+1]+k[c-L+1]; ans=max(ans,ans1); } ans>=0?l=mid:r=mid; } printf("%d",(int)(r*1000)); }
Information
- ID
- 167
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 42
- Accepted
- 12
- Uploaded By