ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#193806 | #3399. average | xv_hyy | 100 | 27ms | 2708kb | C++11 | 1.0kb | 2023-10-14 14:55:44 | 2023-10-14 18:37:48 |
answer
#include<bits/stdc++.h>
using namespace std;
#define ls(p) (p<<1)
#define rs(p) (ls(p)^1)
#define int long long
typedef pair<int,int> pii;
//typedef long long ll;
const int mod=1e9+7;
const double eps=1e-6;
const int INF=9223372036854775807;
const int N=1e5+5;
int a[N],s[N],n,k;
inline int read();
inline bool check(int x){
int minn=1e18;
for(int i=1;i<=n;++i){
s[i]=s[i-1]+a[i]-x;
if(i>=k){
minn=min(minn,s[i-k]);
if(s[i]>=minn){
return true;
}
}
}
return false;
}
inline void solve(){
n=read(),k=read();
int l=1e18,r=0,ans=0;
for(int i=1;i<=n;++i){
a[i]=read();
l=min(l,a[i]);
r=max(r,a[i]);
}
while(l<=r){
int mid=l+r>>1;
if(check(mid))l=mid+1,ans=mid;
else r=mid-1;
}
printf("%lld\n",ans);
}
signed main(){
int T=1;
// int T=read();
while(T--)solve();
return 0;
}
inline int read(){
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
return x*f;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 20
Accepted
time: 0ms
memory: 1164kb
input:
1000 100 332109541 265698305 339007233 386487277 65597920 217218907 436378017 221884663 270433433 26...
output:
334924174
result:
ok single line: '334924174'
Test #2:
score: 20
Accepted
time: 0ms
memory: 1168kb
input:
1000 100 108652253 396843081 18739163 168730297 41598432 22132831 155692945 617160601 164753707 8614...
output:
323746083
result:
ok single line: '323746083'
Test #3:
score: 20
Accepted
time: 0ms
memory: 1168kb
input:
1000 100 71158753 11073019 119630785 162780801 25368543 517705 123835636 254874371 4127795 157084999...
output:
338258685
result:
ok single line: '338258685'
Test #4:
score: 20
Accepted
time: 16ms
memory: 2708kb
input:
100000 10 227552529 170886571 513851125 46675201 188079376 255537313 266819605 69661658 214521435 33...
output:
642253260
result:
ok single line: '642253260'
Test #5:
score: 20
Accepted
time: 11ms
memory: 2708kb
input:
100000 100 227552529 170886571 513851125 46675201 188079376 255537313 266819605 69661658 214521435 3...
output:
353627389
result:
ok single line: '353627389'