提交时间:2023-12-16 08:36:37

运行 ID: 116125

#include<iostream> using namespace std; int n; int a[1001]; int ans1(){ int sum=0; for(int i=1;i<=n;i+=2){ sum+=a[i]; } return sum; } int ans2(){ int sum; for(int i=2;i<=n;i+=2){ sum+=a[i]; } return sum; } int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i]; } int ans=max(ans1(),ans2()); cout<<ans<<endl; return 0; }