09: LGTB credits, 09lgtb credits
-
Total time limit:
-
10000 ms
-
Time limit for a single test point:
-
1000 ms
-
Memory limit:
-
65536kB
-
Description
-
LGTB has been learning chunks recently, but he is too fond of food. He is confused when there are too many chunks, so he can only divide it into three.
Today he got an array, and he suddenly wanted to block it. He wanted to know that the array was divided into three parts, and the block could be empty. Assume that the three blocks have the minimum and medium maximum values.
Output the maximum value in the last three parts.
-
Input
-
The first line of the input contains an integer n representing the array size.
The next n integers a1, a2,..., a n represent arrays.
-
Output
-
The output contains one integer, which indicates the maximum value of the three blocks after the multipart is completed.
-
Sample Input
-
102 5 1 4 7 3 6 2 5 1
-
Sample output
-
14
-
Prompt
-
For 40% of the data, 1 ≤ n ≤ 10
For 70% of the data, 1≤n ≤ 1e3
For 100% of the data, 1 ≤ n ≤ 1e5, 1 ≤ ai ≤ 1e7
- View
- Submit
- Statistics
- Question
-
Global question number
-
7414
-
Submissions
-
14
-
Number of students
-
7
-
Pass count
-
2
Your submission records
# |
Result |
Time |
4 |
Accepted |
07-16 |
3 |
Wrong Answer |
07-16 |
2 |
Time Limit Exceeded |
07-16 |
1 |
Time Limit Exceeded |
07-16 |
- ©2002-2013 POJ Shanghai ICP filing No. 12005590-3
The second answer is a second later. If the second answer is written, the second answer will not be written into l ++, and the second answer will be slow ..
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<cmath> 5 #define lli long long int 6 using namespace std; 7 const lli MAXN=100000001; 8 void read(lli &n) 9 {10 char c='+';lli x=0;bool flag=0;11 while(c<'0'||c>'9'){c=getchar();if(c=='-')flag=1;}12 while(c>='0'&&c<='9')13 x=(x<<1)+(x<<3)+c-48,c=getchar();14 flag==1?n=-x:n=x;15 }16 lli a[MAXN];17 lli l,r;18 lli n;19 bool pd(lli num)20 {21 lli now=0;22 lli tot=0;23 for(lli i=1;i<=n;i++)24 {25 if(now+a[i]<num)26 now+=a[i];27 else if(now+a[i]==num)28 tot++,now=0;29 else if(now+a[i]>num)30 tot++,now=a[i];31 }32 if(now)33 tot++;34 if(tot>3)35 return 0;36 else 37 return 1;38 }39 int main()40 {41 read(n);42 for(lli i=1;i<=n;i++)43 read(a[i]),r+=a[i],l=max(l,a[i]);44 while(l<=r)45 {46 lli mid=(l+r)>>1;47 if(pd(mid))48 r=mid-1;49 else 50 l=mid+1;51 }52 printf("%lld",l);53 return 0;54 }