Untitled
user_9000366
plain_text
21 days ago
716 B
0
Indexable
int main() { int n; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } long long s = 0, d = 0; int i = 0, j = n - 1; bool turn = true; for (;;) { if (turn) { if (a[i] >= a[j]) { s += a[i]; i++; } else { s += a[j]; j--; } } else { if (a[i] >= a[j]) { d += a[i]; i++; } else { d += a[j]; j--; } } turn = !turn; if (i > j)break; } cout << s << " " << d << endl; return 0; }
Editor is loading...
Leave a Comment