QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#883040 | #9961. Cows | zwh2008 | WA | 1ms | 5864kb | C++14 | 1.0kb | 2025-02-05 14:30:22 | 2025-02-05 14:30:22 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const int N=2e5+5;
int n,a[N],b[N],c[N],t[N];
bool chk(int x) {
ll s=0;
for(int i=1;i<=n;i++)b[i]=a[i],s+=x-b[i],t[i]=c[i]=0;
if(s<0)return 0;
ll now=0;
for(int i=1;i<=n;i++) {
if(b[i]>b[i-1]) {
int v=min(t[i],(b[i]-b[i-1]+1)/2);
b[i]=b[i-1]+v+max(0,b[i]-b[i-1]-2*v);
}
auto ck=[&](int y)->bool {
if(i==1)return 1;
if(b[i-1]<y)return b[i-1]<=c[i-1];
int v=b[i-1]-y;
return y+(v+1)/2<=c[i-1];
};
int l=0,r=x,mid,s=-1;
while(l<=r)mid=l+r>>1,ck(mid)?l=mid+1,s=mid:r=mid-1;
if(s==-1)return 0; c[i]=s;
if(b[i]<c[i])t[i+1]+=c[i]-b[i];
}return c[n]>=b[n];
}
int main() {
ios::sync_with_stdio(0),cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++)cin>>a[i];
int l=0,r=1e9,mid,ans;
while(l<=r)mid=l+r>>1,chk(mid)?r=mid-1,ans=mid:l=mid+1;
cout<<ans<<'\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5864kb
input:
5 5 4 0 4 6
output:
4
result:
ok 1 number(s): "4"
Test #2:
score: 0
Accepted
time: 0ms
memory: 5860kb
input:
3 1 4 6
output:
5
result:
ok 1 number(s): "5"
Test #3:
score: 0
Accepted
time: 0ms
memory: 5728kb
input:
1 1
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
1 1000000000
output:
1000000000
result:
ok 1 number(s): "1000000000"
Test #5:
score: -100
Wrong Answer
time: 0ms
memory: 5732kb
input:
8 6 0 5 5 6 3 0 6
output:
5
result:
wrong answer 1st numbers differ - expected: '4', found: '5'