https://codeforces.com/problemset/problem/381/A
#include <bits/stdc++.h>
using namespace std;
int main() {
// your code goes here
#ifndef ONLINE_JUDGE
freopen(“input.txt”, “r”, stdin);
freopen(“output.txt”, “w”, stdout);
#endif
// your code goes here
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int a[n];
for (int i = 0; i < n; i++)
{
cin >> a[i];
}
int i = 0, j = n - 1;
int sums = 0, sumd = 0;
int turn = 1;
while (i <= j)
{
if (a[i] > a[j])
{
if ( turn % 2 == 1)
{
sums += a[i];
}
else
{
sumd += a[i];
}
i++;
}
else
{
if ( turn % 2 == 1)
{
sums += a[j];
}
else
{
sumd += a[j];
}
j--;
}
turn++;
}
cout << max(sums, sumd) << " ";
cout << min(sums, sumd) << "\n";
return 0;
}
Why Iam getting wrong answer for the above problem