Main Topic
Some chocolate bars of different lengths are lined up, a is eaten from left to right, and B is eaten from right to left. Two people eat the same speed, do not allow the suspension, not allowed to eat the hands of the next, when the hands of two people eat at the same time and the next to eat is the same one when the chocolate bar to a eat. Ask them to eat a few at the end.
Thinking of solving problems
Two pointers are left-to-right and right-to-left, respectively. According to the requirements of the subject operation can.
Title Code
#include <set>
#include <map>
#include <queue>
#include <math.h>
#include <vector>
#include <string>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <cctype>
#include <algorithm>
#include <time.h>
#define eps 1e-10
#define pi acos(-1.0)
#define inf 107374182
#define inf64 1152921504606846976
#define lc l,m,tr<<1
#define rc m + 1,r,tr<<1|1
#define zero(a) fabs(a)<eps
#define iabs(x) ((x) > 0 ? (x) : -(x))
#define clear1(A, X, SIZE) memset(A, X, sizeof(A[0]) * (min(SIZE,sizeof(A))))
#define clearall(A, X) memset(A, X, sizeof(A))
#define memcopy1(A , X, SIZE) memcpy(A , X ,sizeof(X[0])*(SIZE))
#define memcopyall(A, X) memcpy(A , X ,sizeof(X))
#define max( x, y ) ( ((x) > (y)) ? (x) : (y) )
#define min( x, y ) ( ((x) < (y)) ? (x) : (y) )
using namespace std;
int num[100005];
int main()
{
int l=0,r=0,lp,rp,n;
scanf("%d",&n);
for(int i=0;i<n;i++)
{
scanf("%d",&num[i]);
}
lp=0;
rp=n-1;
while(lp<=rp)
{
if(l<=r)
{
l+=num[lp++];
}
else r+=num[rp--];
}
printf("%d %d",lp,n-rp-1);
return 0;
}