C. Alice, Bob and Chocolate

题目连接:

http://codeforces.com/contest/6/problem/C

Description

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 Input

5

2 9 8 2 7

Sample Output

2 3

Hint

题意

有n个物品,每个物品吃掉的时间是a[i]

一个人从左边开始吃,一个人从右边开始吃

如果两个人同时吃到了一个东西,算左边的。

最后问你左边吃了多少个,右边吃了多少个

题解:

直接暴力就好了……

一个记录左边吃的时间,一个记录右边吃的时间,不停去扫就好了

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
long long a[maxn];
int main()
{
int n;scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&a[i]);
long long t1=0,t2=0;
int num1=0,num2=0;
int l=1,r=n;
while(l<=r)
{
if(t1<=t2)t1+=a[l++],num1++;
else t2+=a[r--],num2++;
}
cout<<num1<<" "<<num2<<endl;
}

Codeforces Beta Round #6 (Div. 2 Only) C. Alice, Bob and Chocolate 水题的更多相关文章

  1. Codeforces Beta Round #9 (Div. 2 Only) E. Interesting Graph and Apples 构造题

    E. Interesting Graph and Apples 题目连接: http://www.codeforces.com/contest/9/problem/E Description Hexa ...

  2. Codeforces Beta Round #80 (Div. 2 Only)【ABCD】

    Codeforces Beta Round #80 (Div. 2 Only) A Blackjack1 题意 一共52张扑克,A代表1或者11,2-10表示自己的数字,其他都表示10 现在你已经有一 ...

  3. Codeforces Beta Round #83 (Div. 1 Only)题解【ABCD】

    Codeforces Beta Round #83 (Div. 1 Only) A. Dorm Water Supply 题意 给你一个n点m边的图,保证每个点的入度和出度最多为1 如果这个点入度为0 ...

  4. Codeforces Beta Round #79 (Div. 2 Only)

    Codeforces Beta Round #79 (Div. 2 Only) http://codeforces.com/contest/102 A #include<bits/stdc++. ...

  5. Codeforces Beta Round #77 (Div. 2 Only)

    Codeforces Beta Round #77 (Div. 2 Only) http://codeforces.com/contest/96 A #include<bits/stdc++.h ...

  6. Codeforces Beta Round #76 (Div. 2 Only)

    Codeforces Beta Round #76 (Div. 2 Only) http://codeforces.com/contest/94 A #include<bits/stdc++.h ...

  7. Codeforces Beta Round #75 (Div. 2 Only)

    Codeforces Beta Round #75 (Div. 2 Only) http://codeforces.com/contest/92 A #include<iostream> ...

  8. Codeforces Beta Round #74 (Div. 2 Only)

    Codeforces Beta Round #74 (Div. 2 Only) http://codeforces.com/contest/90 A #include<iostream> ...

  9. Codeforces Beta Round #73 (Div. 2 Only)

    Codeforces Beta Round #73 (Div. 2 Only) http://codeforces.com/contest/88 A 模拟 #include<bits/stdc+ ...

随机推荐

  1. .ui/qrc文件自动生成.py文件

    前天PL让我们做一个从手机里手机一些数据导出到excel文件里的Tool. 让我们用python去写一个.但是我们都没有学过python..呵呵! 然后昨天看了一些文档.做ui时还需要把图片写入qrc ...

  2. tomcat+java的web程序持续占cpu高问题调试【转】

    转自 tomcat+java的web程序持续占cpu问题调试 - 像风一样的自由 - CSDN博客http://blog.csdn.net/five3/article/details/28416771 ...

  3. SpringMVC_HelloWorld_03

    通过注解的方式实现一个简单的HelloWorld. 源码 一.新建项目 同SpringMVC_HelloWorld_01 不同的是springmvc配置文件的命名和路径,此处为src/springmv ...

  4. centos7安装lamp

    一.准备工作 1.   下载并安装CentOS7.2,配置好网络环境,确保centos能上网,可以获取到yum源. centos7.2的网络配置: vim /etc/sysconfig/network ...

  5. FAQ1: 列表索引和切片问题

    问题1. 超过列表成员个数的索引访问列表会出现IndexError错误,但是如果用切片去访问就不会报错,而是返回一个空列表.同样元组也是. >>> a=[1,2,3,4] >& ...

  6. geoip 扩展包根据ip定位详情

    教程:https://laravel-china.org/courses/laravel-package/2024/get-the-corresponding-geo-location-informa ...

  7. Linux Supervisor的安装与使用入门---SuSE

    Linux Supervisor的安装与使用入门 在linux或者unix操作系统中,守护进程(Daemon)是一种运行在后台的特殊进程,它独立于控制终端并且周期性的执行某种任务或等待处理某些发生的事 ...

  8. system()函数

    windows下system () 函数详解 windows操作系统下system () 函数详解(主要是在C语言中的应用) 函数名: system   功 能: 发出一个DOS命令   用 法: i ...

  9. ueditor 编辑器上传到服务器后图片上传不能正常使用

    网站集成ueditor编辑器后在本地能正常使用,上传到服务器上后,图片上传功能提示:后端配置项没有正常加载,上传插件不能正常使用.且单个图片上传图标是灰色的不能点击. 相信遇到这个问题的同学是很多的吧 ...

  10. Unity3D 向量运算

    写在前面的话,前两天有个朋友在QQ上问我 如何获取主角面朝方向一定区域中的敌人对象.这个命题看似简单,其实里面蕴含了很多数学方面的东西.今天刚好有时间我就彻底的把这个疑问写在博客中.希望可以帮助到他. ...