Submission #341464

# Submission time Handle Problem Language Result Execution time Memory
341464 2020-12-29T19:12:31 Z ogibogi2004 Bigger segments (IZhO19_segments) C++14
0 / 100
1 ms 364 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll INF=2e17;
const int MAXN=5e5+6;
ll a[MAXN],n;
ll pref[MAXN];
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	reverse(a+1,a+n+1);
	for(int i=1;i<=n;i++)a[i]=-a[i];
	for(int i=1;i<=n;i++)
	{
		pref[i]=pref[i-1]+a[i];
	}
	ll last=-INF,l=1,cnt=1;
	while(l!=n+1)
	{
		//cout<<l<<"\n";
		int j=n;
		for(int i=l;i<=n;i++)
		{
			if(pref[i]-pref[l-1]<last)continue;
			//cout<<i<<" ";
			int low=i+1,high=n-1,mid,ans=-1;
			while(low<=high)
			{
				mid=(low+high)/2;
				if(pref[mid]-pref[i]>=pref[i]-pref[l-1])
				{
					ans=mid;
					low=mid+1;
				}
				else high=mid-1;
			}
			cout<<ans<<endl;
			if(ans==-1)continue;
			//cout<<l<<" "<<ans<<endl;
			if(pref[n]-pref[ans]<pref[ans]-pref[i])continue;
			j=i;break;
		}
		cnt++;
		last=pref[j]-pref[l-1];
		l=j+1;
	}
	cout<<max(1ll,cnt)<<endl;
return 0;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -