Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // main.cpp
- // olymp_in
- //
- // Created by Kadir Kadyrov on 19.10.2020.
- // Copyright © 2020 Kadir Kadyrov. All rights reserved.
- //
- #include <iostream>
- #include <algorithm>
- #include <string>
- #include <cstdio>
- #include <queue>
- #include <map>
- #include <vector>
- #include <stack>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- int a[n];
- for (int i = 0; i < n; i++) {
- cin >> a[i];
- }
- int l = 0, r = n - 1;
- int ansS = 0, ansD = 0;
- bool isTurnOfSergey = true;
- while (l <= r) {
- if (isTurnOfSergey == true) {
- if (a[l] > a[r]) {
- ansS += a[l];
- l++;
- } else {
- ansS += a[r];
- r--;
- }
- isTurnOfSergey = false;
- } else {
- if (a[l] > a[r]) {
- ansD += a[l];
- l++;
- } else {
- ansD += a[r];
- r--;
- }
- isTurnOfSergey = true;
- }
- }
- cout << ansS << ' ' << ansD << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement