Codeforces 6C. Alice, Bob and Chocolate

来源:互联网 发布:js如何创建数组 编辑:程序博客网 时间:2024/05/16 17:34

C. Alice, Bob and Chocolate
time limit per test
2 seconds
memory limit per test
64 megabytes
input
standard input
output
standard output

Alice and Bob like games. And now they are ready to start a new game. They have placed n chocolate bars in a line. Alice starts to eat chocolate bars one by one from left to right, and Bob — from right to left. For each chocololate bar the time, needed for the player to consume it, is known (Alice and Bob eat them with equal speed). When the player consumes a chocolate bar, he immediately starts with another. It is not allowed to eat two chocolate bars at the same time, to leave the bar unfinished and to make pauses. If both players start to eat the same bar simultaneously, Bob leaves it to Alice as a true gentleman.

How many bars each of the players will consume?

Input

The first line contains one integer n (1 ≤ n ≤ 105) — the amount of bars on the table. The second line contains a sequence t1, t2, ..., tn(1 ≤ ti ≤ 1000), where ti is the time (in seconds) needed to consume the i-th bar (in the order from left to right).

Output

Print two numbers a and b, where a is the amount of bars consumed by Alice, and b is the amount of bars consumed by Bob.

Sample test(s)
input
52 9 8 2 7
output
2 3

代码:

#include <stdio.h>const int MAXN = 100005;int seq[MAXN];int main(){#ifdef _LOCAL    freopen("F://input.txt", "r", stdin);#endif  int n;  scanf("%d", &n);  for(int i = 1; i <= n; ++i)      scanf("%d", &seq[i]);  if(n == 1)  {      printf("1 0\n");      return 0;  }  int first = 1, last = n, eatA = seq[first], eatB = seq[last];  while(1)  {      if(eatA <= eatB && first + 1 < last)          eatA += seq[++first];      else if(eatB < eatA && last - 1 > first)          eatB += seq[--last];      else          break;  }  printf("%d %d", first, n - last + 1);  return 0;}




0 0