Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate(水题)

C. Alice, Bob and Chocolate

time limit per test:2 seconds

memory limit per test:64 megabytes

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.

题意:现在有n个巧克力酒吧,Alice从左边开始消费,Bob从右边开始消费,当Alice和Bob同时要进入同一家酒吧是,Bob会让Alice消费。问Alice和Bob分别消费了多少家酒吧。

import java.util.Collections;
import java.util.Scanner;
import java.util.*;
public class First {
	static int c[]=new int[100010];
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		int n=input.nextInt(),alice=0,bob=0,a=0,b=n-1;
		for(int i=0;ibob) {
				bob+=c[b];
				b--;
			}
			if(a>b)
				break;
		}
		System.out.printf("%d %d\n",a,n-a);
	}
}

 

你可能感兴趣的:(Codeforces)