We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3dc0180 commit 992e3feCopy full SHA for 992e3fe
381A - Sereja and Dima.cpp
@@ -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
37
38
39
40
+ Dima+=cards[l];
41
42
43
44
45
+ Dima+=cards[r];
46
47
48
49
+ c++;
50
51
+ cout<<Sereja<<" "<<Dima<<endl;
52
+}
0 commit comments