CF6C Alice, Bob and Chocolate

CF6C Alice, Bob and Chocolate

题目链接

写了一天搜索写的有点累了,就顺手水了一道CF的模拟题

这道题就是简单的模拟整个题的过程,注意最后输出的形式就好了QWQ

AC代码如下:

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define MAXN 500000
using namespace std;
int G[MAXN];
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&G[i]);
	}
	int a=1;
	int b=n;
	for(int cur1=0,cur2=0;a<=b;)
	{
		if(cur1<=cur2)
		{
			cur1=cur1+G[a++];
		}
		else
		{
			cur2=cur2+G[b--];
		}
	}
	printf("%d %d",a-1,n-b);
	return 0;
}
原文地址:https://www.cnblogs.com/LITTLESUNwl/p/10679437.html