Codeforces962 A. Equator

tech2023-01-21  85

Polycarp has created his own training plan to prepare for the programming contests. He will train for 𝑛 days, all days are numbered from 1 to 𝑛, beginning from the first.

On the 𝑖-th day Polycarp will necessarily solve 𝑎𝑖 problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.

Determine the index of day when Polycarp will celebrate the equator.

Input The first line contains a single integer 𝑛 (1≤𝑛≤200000) — the number of days to prepare for the programming contests.

The second line contains a sequence 𝑎1,𝑎2,…,𝑎𝑛 (1≤𝑎𝑖≤10000), where 𝑎𝑖 equals to the number of problems, which Polycarp will solve on the 𝑖-th day.

Output Print the index of the day when Polycarp will celebrate the equator.

Examples inputCopy 4 1 3 2 1 outputCopy 2 inputCopy 6 2 2 2 2 2 2 outputCopy 3 Note In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve 4 out of 7 scheduled problems on four days of the training.

In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve 6 out of 12 scheduled problems on six days of the training.

不解释。。。

#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include <set> #include <map> #include <queue> using namespace std; typedef long long ll; const int maxn = 2e5 + 7; int a[maxn]; int main() { int n;scanf("%d",&n); int sum = 0; for(int i = 1;i <= n;i++) { scanf("%d",&a[i]); sum += a[i]; } int now = 0; for(int i = 1;i <= n;i++) { now += a[i]; if(now >= (sum + 1) / 2) { printf("%d\n",i); return 0; } } return 0; }
最新回复(0)