-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSolution-CF381-D2-A
48 lines (46 loc) · 1.44 KB
/
Solution-CF381-D2-A
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
#include <iostream>
using namespace std;
int main()
{
int numberOfCards=0,sCards=0,dCards=0;
cin>>numberOfCards;
int temp=numberOfCards;
int arrayOfCards[numberOfCards];
for(int index1=0;index1<numberOfCards;index1++){
cin>>arrayOfCards[index1];
}
for(int index2=1;index2<=numberOfCards;index2++){
if(index2%2==1){
if(arrayOfCards[0]>=arrayOfCards[temp-1]){
sCards+=arrayOfCards[0];
for(int index3=0;index3<temp-1;index3++){
arrayOfCards[index3]=arrayOfCards[index3+1];
}
arrayOfCards[temp-1]=0;
temp-=1;
}
else if(arrayOfCards[0]<arrayOfCards[temp-1]){
sCards+=arrayOfCards[temp-1];
arrayOfCards[temp-1]=0;
temp-=1;
}
}
else if(index2%2==0){
if(arrayOfCards[0]>=arrayOfCards[temp-1]){
dCards+=arrayOfCards[0];
for(int index3=0;index3<temp-1;index3++){
arrayOfCards[index3]=arrayOfCards[index3+1];
}
arrayOfCards[temp-1]=0;
temp-=1;
}
else if(arrayOfCards[0]<arrayOfCards[temp-1]){
dCards+=arrayOfCards[temp-1];
arrayOfCards[temp-1]=0;
temp-=1;
}
}
}
cout<<sCards<<" "<<dCards<<endl;
return 0;
}