Loading Similar Posts
Question 01 soln:
#include <bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin>>n;
vector<int> arr(n);
for(int i=0; i<n; i++){
cin>>arr[i];
}
bool flag = 0;
int i=0, j=n-1;
bool turn = 0;
int s1 = 0, s2 = 0;
while(i<=j){
if(flag == 0){
flag = (arr[i]%2 == 0) ? 1-flag : flag;
if(turn == 0) s1 += arr[i];
else s2 += arr[i];
turn = 1-turn;
i++;
}else{
flag = (arr[j]%2 == 0) ? 1-flag : flag;
if(turn == 0) s1 += arr[j];
else s2 += arr[j];
turn = 1-turn;
j--;
}
}
cout<<s1<<" "<<s2<<endl;
}
int main()
{
int t;
// cin>>t;
t=1;
while(t--){
solve();
}
}