Skip to content

Commit 992e3fe

Browse files
committed
Added 381A - Sereja and Dima.cpp
1 parent 3dc0180 commit 992e3fe

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

381A - Sereja and Dima.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#include<bits/stdc++.h>
2+
using namespace std;
3+
4+
// Code Written By: Vikash Patel
5+
6+
// Codeforces Profile: https://codeforces.com/profile/vikashpatel
7+
8+
int main()
9+
{
10+
int n;
11+
cin>>n;
12+
int cards[n];
13+
for(int i=0;i<n;i++)
14+
{
15+
cin>>cards[i];
16+
}
17+
int Sereja, Dima;
18+
Sereja = Dima = 0;
19+
int c=0;
20+
int l=0,r=n-1;
21+
while(n--)
22+
{
23+
if(c%2==0)
24+
{
25+
if(cards[l]>cards[r])
26+
{
27+
Sereja+=cards[l];
28+
l++;
29+
}
30+
else
31+
{
32+
Sereja+=cards[r];
33+
r--;
34+
}
35+
}
36+
else
37+
{
38+
if(cards[l]>cards[r])
39+
{
40+
Dima+=cards[l];
41+
l++;
42+
}
43+
else
44+
{
45+
Dima+=cards[r];
46+
r--;
47+
}
48+
}
49+
c++;
50+
}
51+
cout<<Sereja<<" "<<Dima<<endl;
52+
}

0 commit comments

Comments
 (0)