Submission #55140

# Submission time Handle Problem Language Result Execution time Memory
55140 2018-07-06T06:18:04 Z 김세빈(#1527) None (JOI14_ho_t3) C++11
0 / 100
3 ms 540 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll A[202020];
ll n, sum;

bool check(ll k)
{
	ll i, j, l, s1, s2;
	s1 = s2 = 0;
	
	for(i=j=l=1;i<=n;i++){
		for(;j<=n+i && s1<k;j++) s1 += A[j], s2 -= A[j];
		for(;l<=n+i && s2<s1;l++) s2 += A[l];
		if(s2 >= s1 && sum - s2 - s1 >= s1) return 1;
		s1 -= A[i];
	}
	
	return 0;
}

int main()
{
	ll i, s, e, mid;
	
	scanf("%lld", &n);
	
	for(i=1;i<=n;i++){
		scanf("%lld", A+i);
		sum += A[i];
		A[n+i] = A[i];
	}
	
	for(s=0,e=1e18;s<=e;){
		mid = s+e>>1;
		if(check(mid)) s = mid+1;
		else e = mid-1;
	}
	
	check(1);
	
	printf("%lld\n", s-1);
	
	return 0;
}

Compilation message

2014_ho_t3.cpp: In function 'int main()':
2014_ho_t3.cpp:38:10: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   mid = s+e>>1;
         ~^~
2014_ho_t3.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld", &n);
  ~~~~~^~~~~~~~~~~~
2014_ho_t3.cpp:32:8: 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 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Incorrect 2 ms 540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Incorrect 2 ms 540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Incorrect 2 ms 540 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 540 KB Output is correct
4 Incorrect 2 ms 540 KB Output isn't correct
5 Halted 0 ms 0 KB -