water problem. The general idea is to find the smallest prefix sum that is greater than or equal to half the sum. Just scan and compare. It is worth noting that if the sum is an odd number, sum=sum/2+1. Because this wa one shot
#include <iostream> #include <bits/stdc++.h> using namespace std; int a[200005]; intmain() { int n,i,sum=0; scanf("%d",&n); for(i=0;i<n;i++) { scanf("%d",a+i); sum+=a[i]; } if(sum%2==0) { sum/=2; } else { sum = sum/2+1; } int temp=0,flag; for(i=0;i<n;i++) { temp+=a[i]; if(temp>=sum) { flag=i; break; } } printf("%d\n",flag+1); return 0; }