Codeforces 962A Equator(瞎搞)

题目链接:Equator

题意

Polycarp P o l y c a r p 总共要刷 n n 天的题,第 i 天他刷了 ai a i 道题,他想要在刷题量达到总量的一半的那天晚上庆祝一下,问他将在第几天庆祝。

输入

第一行为一个整数 n (1n2×105) n   ( 1 ≤ n ≤ 2 × 10 5 ) ,第二行包含 n n 个整数 a1,a2,,an (1ai104)

输出

输出他将在第几天庆祝,天数从 1 1 开始计算。

样例

输入
4
1 3 2 1
输出
2
提示
到第 2 天晚上的时候他刷了 4 4 题,他的总刷题量为 7 题,达到了总刷题量的一半。

输入
6
2 2 2 2 2 2
输出
3
提示
到第 3 3 天晚上的时候他刷了 6 题,他的总刷题量为 12 12 题,达到了总刷题量的一半。
题解

按题意扫两遍数组。

过题代码

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <iomanip>
using namespace std;

#define LL long long
const int maxn = 200000 + 100;
int n, ans;
LL half, sum;
LL num[maxn];

int main() {
    #ifdef LOCAL
    freopen("test.txt", "r", stdin);
//        freopen("out.txt", "w", stdout);
    #endif // LOCAL
    ios::sync_with_stdio(false);

    while(scanf("%d", &n) != EOF) {
        half = sum = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%I64d", &num[i]);
            sum += num[i];
        }
        for(int i = 1; i <= n; ++i) {
            half += num[i];
            if(half * 2 >= sum) {
                ans = i;
                break;
            }
        }
        printf("%d\n", ans);
    }

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值