Submission #31601

# Submission time Handle Problem Language Result Execution time Memory
31601 2017-08-30T02:41:47 Z huynd2001 Hacker (BOI15_hac) C++14
100 / 100
106 ms 15844 KB
/*huypheu
5
1 1 1 1 1
*/

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

int a[500007];
int su[500007];
int ar[500007];

signed main()
{
	int n;
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	int k=(n/2)+(n%2!=0);
	for(int i=1;i<=n;i++)
	{
		su[i]=su[i-1]+a[i];
	}
	for(int i=1;i<=n;i++)
	{
		if(i+k-1<=n) 
		{
			ar[i]=su[i+k-1]-su[i-1];
		}
		else
		{
			ar[i]=su[n]-su[i-1]+su[k-(n-i+1)];
		}
	}
	// for(int i=1;i<=n;i++) cout << ar[i] << endl;
	for(int i=n+1;i<=2*n;i++)
	{
		ar[i]=ar[i-n];
	}
	deque <int> deq;
	int ans=0;
	for(int i=1;i<=2*n;i++)
	{
		while(!deq.empty() && deq.front()<=(i-k)) deq.pop_front();
		while(!deq.empty() && ar[deq.back()]>ar[i]) deq.pop_back();
		deq.push_back(i);
		if(i>=k) ans=max(ans,ar[deq.front()]);
	}
	printf("%lld",ans);
	// int mi=0;
	// for(int i=2;i<=n-la+1;i++)
	// {
	// 	mi=max(mi,su[i+la-1]-su[i-1]);
	// }
	// printf("%lld",su[n]-mi);
	return 0;
}

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:17:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&n);
                  ^
hac.cpp:20:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&a[i]);
                      ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
19 Correct 0 ms 13732 KB Output is correct
20 Correct 0 ms 13732 KB Output is correct
21 Correct 0 ms 13732 KB Output is correct
22 Correct 0 ms 13732 KB Output is correct
23 Correct 0 ms 13732 KB Output is correct
24 Correct 0 ms 13732 KB Output is correct
25 Correct 0 ms 13732 KB Output is correct
26 Correct 0 ms 13732 KB Output is correct
27 Correct 0 ms 13732 KB Output is correct
28 Correct 0 ms 13732 KB Output is correct
29 Correct 0 ms 13732 KB Output is correct
30 Correct 0 ms 13732 KB Output is correct
31 Correct 0 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 13 ms 13732 KB Output is correct
5 Correct 39 ms 13732 KB Output is correct
6 Correct 43 ms 13732 KB Output is correct
7 Correct 56 ms 13732 KB Output is correct
8 Correct 106 ms 13732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 13732 KB Output is correct
2 Correct 0 ms 13732 KB Output is correct
3 Correct 0 ms 13732 KB Output is correct
4 Correct 0 ms 13732 KB Output is correct
5 Correct 0 ms 13732 KB Output is correct
6 Correct 0 ms 13732 KB Output is correct
7 Correct 0 ms 13732 KB Output is correct
8 Correct 0 ms 13732 KB Output is correct
9 Correct 0 ms 13732 KB Output is correct
10 Correct 0 ms 13732 KB Output is correct
11 Correct 0 ms 13732 KB Output is correct
12 Correct 0 ms 13732 KB Output is correct
13 Correct 0 ms 13732 KB Output is correct
14 Correct 0 ms 13732 KB Output is correct
15 Correct 0 ms 13732 KB Output is correct
16 Correct 0 ms 13732 KB Output is correct
17 Correct 0 ms 13732 KB Output is correct
18 Correct 0 ms 13732 KB Output is correct
19 Correct 0 ms 13732 KB Output is correct
20 Correct 0 ms 13732 KB Output is correct
21 Correct 0 ms 13732 KB Output is correct
22 Correct 0 ms 13732 KB Output is correct
23 Correct 0 ms 13732 KB Output is correct
24 Correct 0 ms 13732 KB Output is correct
25 Correct 0 ms 13732 KB Output is correct
26 Correct 0 ms 13732 KB Output is correct
27 Correct 0 ms 13732 KB Output is correct
28 Correct 0 ms 13732 KB Output is correct
29 Correct 0 ms 13732 KB Output is correct
30 Correct 0 ms 13732 KB Output is correct
31 Correct 0 ms 13732 KB Output is correct
32 Correct 0 ms 13732 KB Output is correct
33 Correct 0 ms 13732 KB Output is correct
34 Correct 0 ms 13732 KB Output is correct
35 Correct 13 ms 13732 KB Output is correct
36 Correct 39 ms 13732 KB Output is correct
37 Correct 43 ms 13732 KB Output is correct
38 Correct 56 ms 13732 KB Output is correct
39 Correct 106 ms 13732 KB Output is correct
40 Correct 0 ms 13732 KB Output is correct
41 Correct 3 ms 13732 KB Output is correct
42 Correct 0 ms 13732 KB Output is correct
43 Correct 33 ms 13732 KB Output is correct
44 Correct 89 ms 13732 KB Output is correct
45 Correct 16 ms 13732 KB Output is correct
46 Correct 56 ms 13732 KB Output is correct
47 Correct 93 ms 13732 KB Output is correct
48 Correct 59 ms 15844 KB Output is correct
49 Correct 66 ms 15844 KB Output is correct
50 Correct 79 ms 15844 KB Output is correct