Skip to content

Commit ff0cf2a

Browse files
committed
Added problem 1006C (JS - Codeforces)
1 parent 885fa3d commit ff0cf2a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

codeforces/js/1006C.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/**
2+
* Three Parts of the Array
3+
* https://codeforces.com/problemset/problem/1006/C
4+
*/
5+
var nElements = +readline();
6+
var elements = readline().split(' ').map(Number);
7+
8+
var index1 = 0;
9+
var index2 = nElements - 1;
10+
var maxSum = 0;
11+
var maxIndex1 = 0;
12+
var maxIndex2 = 0;
13+
var sum1 = elements[0];
14+
var sum2 = elements[index2];
15+
16+
while (index1 < index2) {
17+
if(sum1 < sum2) {
18+
index1++;
19+
sum1 += elements[index1];
20+
} else if(sum1 === sum2) {
21+
// Save this case
22+
maxSum = sum1;
23+
maxIndex1 = index1;
24+
maxIndex2 = index2;
25+
26+
// Search for best case
27+
index1++;
28+
index2--;
29+
sum1 += elements[index1];
30+
sum2 += elements[index2];
31+
} else {
32+
index2--;
33+
sum2 += elements[index2];
34+
}
35+
}
36+
37+
print(maxSum);

0 commit comments

Comments
 (0)