Submission #63001

# Submission time Handle Problem Language Result Execution time Memory
63001 2018-07-31T08:15:13 Z zetapi Rice Hub (IOI11_ricehub) C++14
100 / 100
44 ms 15524 KB
#include "ricehub.h"

#include <bits/stdc++.h>
using namespace std;

#define pb  push_back
#define mp  make_pair
#define ll	long long
#define itr ::iterator 

typedef pair<int,int>  pii;

const int MAX=1e5;

int N,arr[MAX];

int cal(int ind,ll left)
{
	int pre=ind-1,nxt=ind,res=0;
	while(left>=0 and (pre>=0 or nxt<N))
	{
		if(pre<0 or (nxt<N and arr[ind]-arr[pre]>arr[nxt]-arr[ind]))
		{
			if(arr[nxt]-arr[ind]>left)
				break;
			left-=arr[nxt]-arr[ind];
			res++;
			nxt++;
		}
		else
		{
			if(arr[ind]-arr[pre]>left)
				break;
			left-=arr[ind]-arr[pre];
			res++;
			pre--;
		}	
	}
	return res;
}

ll sum[MAX];

ll cal(int L,int R)
{
	ll mid=(L+R)/2,bt=mid-L+1,at=R-mid+1;
	return arr[mid]*bt-(sum[mid]-sum[L-1])+(sum[R]-sum[mid-1])-arr[mid]*at;
}

int besthub(int R, int L, int X[], long long B)
{
	int res=0;
	N=R;
	for(int A=0;A<N;A++)
		arr[A+1]=X[A];
	for(int A=1;A<=N;A++)
	{
		sum[A]=sum[A-1]+arr[A];
		int low=1,high=A,mid;
		while(low<=high)
		{
			mid=(low+high)/2;
			if(cal(mid,A)<=B)
			{
				res=max(res,A-mid+1);
				high=mid-1;
			}
			else
				low=mid+1;
		}
	}
	//cout<<cal(3,5)<<"\n";
	return res;
}

/*signed main()
{
	ios_base::sync_with_stdio(false);

	int X[]={1,2,10,12,14};
	cout<<besthub(5,20,X,6);	
	return 0;
}*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Correct 3 ms 508 KB Output is correct
4 Correct 2 ms 508 KB Output is correct
5 Correct 2 ms 508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 524 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 ms 600 KB Output is correct
4 Correct 2 ms 600 KB Output is correct
5 Correct 2 ms 600 KB Output is correct
6 Correct 2 ms 600 KB Output is correct
7 Correct 2 ms 600 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 600 KB Output is correct
10 Correct 2 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 3 ms 620 KB Output is correct
15 Correct 3 ms 620 KB Output is correct
16 Correct 2 ms 736 KB Output is correct
17 Correct 3 ms 736 KB Output is correct
18 Correct 2 ms 736 KB Output is correct
19 Correct 2 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 3 ms 748 KB Output is correct
23 Correct 3 ms 748 KB Output is correct
24 Correct 2 ms 748 KB Output is correct
25 Correct 2 ms 748 KB Output is correct
26 Correct 2 ms 748 KB Output is correct
27 Correct 2 ms 748 KB Output is correct
28 Correct 3 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 748 KB Output is correct
3 Correct 2 ms 748 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 748 KB Output is correct
6 Correct 3 ms 748 KB Output is correct
7 Correct 5 ms 748 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 2 ms 748 KB Output is correct
11 Correct 3 ms 748 KB Output is correct
12 Correct 2 ms 748 KB Output is correct
13 Correct 2 ms 748 KB Output is correct
14 Correct 2 ms 748 KB Output is correct
15 Correct 2 ms 748 KB Output is correct
16 Correct 2 ms 748 KB Output is correct
17 Correct 2 ms 748 KB Output is correct
18 Correct 2 ms 748 KB Output is correct
19 Correct 3 ms 748 KB Output is correct
20 Correct 3 ms 748 KB Output is correct
21 Correct 3 ms 748 KB Output is correct
22 Correct 4 ms 748 KB Output is correct
23 Correct 4 ms 748 KB Output is correct
24 Correct 4 ms 748 KB Output is correct
25 Correct 4 ms 748 KB Output is correct
26 Correct 4 ms 748 KB Output is correct
27 Correct 5 ms 748 KB Output is correct
28 Correct 4 ms 748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 892 KB Output is correct
2 Correct 8 ms 892 KB Output is correct
3 Correct 44 ms 3324 KB Output is correct
4 Correct 36 ms 4316 KB Output is correct
5 Correct 26 ms 4316 KB Output is correct
6 Correct 17 ms 4316 KB Output is correct
7 Correct 35 ms 5856 KB Output is correct
8 Correct 32 ms 6660 KB Output is correct
9 Correct 15 ms 6660 KB Output is correct
10 Correct 18 ms 6660 KB Output is correct
11 Correct 35 ms 8280 KB Output is correct
12 Correct 35 ms 9408 KB Output is correct
13 Correct 17 ms 9408 KB Output is correct
14 Correct 17 ms 9408 KB Output is correct
15 Correct 28 ms 10544 KB Output is correct
16 Correct 43 ms 11332 KB Output is correct
17 Correct 33 ms 12468 KB Output is correct
18 Correct 29 ms 13448 KB Output is correct
19 Correct 29 ms 14520 KB Output is correct
20 Correct 30 ms 15524 KB Output is correct