-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Sereja_and_Dima.cpp
53 lines (48 loc) · 975 Bytes
/
B_Sereja_and_Dima.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <deque>
using namespace std;
int main()
{
int n;
int sareejaScore = 0, dimaScore = 0;
cin >> n;
deque<int> dq;
int x;
for (int i = 0; i < n; i++)
{
cin >> x;
dq.push_back(x);
}
bool SareejasTurn = true;
while (!dq.empty())
{
int numToBeAdded;
if (dq.size() >= 2)
{
numToBeAdded = max(dq.front(), dq.back());
if (dq.front() > dq.back())
{
dq.pop_front();
}
else
{
dq.pop_back();
}
}
else
{
numToBeAdded = dq.front();
dq.pop_front();
}
if (SareejasTurn)
{
sareejaScore += numToBeAdded;
}
else
{
dimaScore += numToBeAdded;
}
SareejasTurn = !SareejasTurn;
}
cout << sareejaScore << " " << dimaScore;
}