CF 6 C. Alice, Bob and Chocolate
思路:就是找处于最中间的值,然后特别判断一下
#include <cstdio> #include <iostream> #include <cmath> #include <algorithm> #include <cstring> using namespace std; int num[100010]; int main() { int n; scanf("%d",&n); long long sum=0; for(int i=1;i<=n;i++) { scanf("%d",&num[i]); sum+=num[i]; } long long total=0; int cnt=1; for(int i=1;i<=n;i++) { if(total+num[i]>sum/2) { cnt=i; break; } total+=num[i]; } long long miao=sum-total-num[cnt]; if(total>miao) cnt--; cout<<cnt<<" "<<n-cnt<<endl; return 0; }