Submission #522624

# Submission time Handle Problem Language Result Execution time Memory
522624 2022-02-05T09:36:30 Z cig32 Rice Hub (IOI11_ricehub) C++17
100 / 100
29 ms 3268 KB
#include "ricehub.h"
#define MAXN 100100
#include<algorithm>
using namespace std;
 
long long arr[MAXN];
long long sum[MAXN];
 
int besthub(int R, int L, int X[], long long B)
{
	sort(X,X+R);
	for(int i=0;i<R;i++) arr[i+1]=X[i];
	for(int i=1;i<=R;i++) sum[i]=sum[i-1]+arr[i];
	
	int ans=0;
	for(int i=1;i<=R;i++)
	{
		int lo=0; 
		int hi=min(R-i+1,i);
		while(lo+1!=hi)
		{
			int mi=(lo+hi)/2;
			long long C=sum[i+mi]-sum[i]-sum[i-1]+sum[i-mi-1];
			if(C<=B)
				lo=mi;
			else hi=mi;
		}
		ans=max(ans,2*lo+1);
	}
	for(int i=1;i<=R-1;i++)
	{
		int lo=-1;
		int hi=min(R-i,i);
		while(lo+1!=hi)
		{
			int mi=(lo+hi)/2;
			long long C=arr[i+1] - arr[i] + sum[i+mi+1] - sum[i+1] - sum[i-1] + sum[i-mi-1];
			if(C<=B)
				lo=mi;
			else hi=mi;
		}
		ans=max(ans,2*lo+2);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 0 ms 204 KB Output is correct
12 Correct 0 ms 204 KB Output is correct
13 Correct 0 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 0 ms 204 KB Output is correct
19 Correct 0 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 0 ms 204 KB Output is correct
22 Correct 0 ms 204 KB Output is correct
23 Correct 0 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 0 ms 204 KB Output is correct
26 Correct 0 ms 204 KB Output is correct
27 Correct 0 ms 204 KB Output is correct
28 Correct 0 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 0 ms 204 KB Output is correct
10 Correct 0 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 1 ms 204 KB Output is correct
16 Correct 0 ms 204 KB Output is correct
17 Correct 1 ms 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 2 ms 332 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 2 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 588 KB Output is correct
2 Correct 4 ms 588 KB Output is correct
3 Correct 21 ms 2184 KB Output is correct
4 Correct 29 ms 3268 KB Output is correct
5 Correct 12 ms 1532 KB Output is correct
6 Correct 13 ms 1520 KB Output is correct
7 Correct 21 ms 2876 KB Output is correct
8 Correct 23 ms 2884 KB Output is correct
9 Correct 11 ms 1532 KB Output is correct
10 Correct 12 ms 1476 KB Output is correct
11 Correct 28 ms 3268 KB Output is correct
12 Correct 26 ms 3240 KB Output is correct
13 Correct 10 ms 1596 KB Output is correct
14 Correct 11 ms 1612 KB Output is correct
15 Correct 21 ms 2488 KB Output is correct
16 Correct 18 ms 2500 KB Output is correct
17 Correct 23 ms 2960 KB Output is correct
18 Correct 22 ms 2864 KB Output is correct
19 Correct 22 ms 3128 KB Output is correct
20 Correct 25 ms 3012 KB Output is correct