2158A - Suspension Idea & Solution: kingmessi
Each red card immediately suspends a player. What is the best way to use $$$r$$$ red cards to maximize the number of distinct suspended players?
A player is suspended after receiving 2 yellow cards. With $$$y$$$ yellow cards, what is the maximum number of players you can suspend using only yellows?
If you add the maximum suspensions from red cards and yellow cards, can this total ever exceed $$$n$$$? What should happen with extra cards in that case?
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n,y,r;
cin >> n;
cin >> y >> r;
cout << min(n,r+y/2) << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
How do you calculate the minimum number of players suspended from the game possible?
2158B - Split Idea & Solution: kingmessi
Does the contribution of an element depend on its exact split $$$(u, v)$$$, or only on whether $$$u$$$ and $$$v$$$ are odd or even?
If every distinct element contributed its maximum possible amount, what would be the upper bound of the answer?
Elements with frequency of the form $$$4k+2$$$ can be split as $$$(2k+1,\,2k+1)$$$, creating $$$0$$$ size imbalance. Elements with frequency of the form $$$4k$$$ can be split as $$$(2k-1,\,2k+1)$$$, creating $$$2$$$ size imbalance.
The number of elements with odd total frequency is always even. How can these elements help correct any size imbalance?
In which situation does the size imbalance become impossible to fix, making the upper bound unreachable?
Consider the case when the number of distinct elements with frequency of the form $$$4k$$$ is odd. What happens if there exists at least one element with odd frequency? What happens if there are no elements with odd frequency?
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n;
cin >> n;
vector<int> a(2*n);
for(int i = 0;i < 2*n;i++){
cin >> a[i];
}
vector<int> cnt(2*n+1);
for(auto &x : a)cnt[x]++;
int x = 0,y = 0,z = 0;
for(int i = 1;i <= 2*n;i++){
if(cnt[i] == 0)continue;
if(cnt[i]&1)x++; //odd elements
else if(cnt[i]%4)y++; //element of form 4*k + 2
else z++; //element of form 4*k
}
int ans = x+2*y+2*z;
if((z&1) && x == 0)ans -= 2;
cout << ans << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
2158C - Annoying Game Idea & Solution: kingmessi
If Alice makes a move and Bob immediately performs the opposite move on the same index (and vice versa), what happens to the array?
How does the parity of $$$k$$$ affect who makes the last move and therefore who can enforce the final uncancelled change?
Using the cancellation idea, can the entire game be reduced to a simpler one with exactly $$$k \bmod 2$$$ effective moves?
If Alice changes $$$a_i$$$, only subarrays containing $$$i$$$ can improve. What are the maximum-sum subarrays that end at $$$i$$$ and start at $$$i$$$, and how can combining them give the best subarray passing through $$$i$$$?
#include<bits/stdc++.h>
using namespace std;
void solve(){
int n,k;
cin >> n >> k;
vector<int> a(n),b(n);
for(int i = 0;i < n;i++)cin >> a[i];
for(int i = 0;i < n;i++)cin >> b[i];
k &= 1; //It can be reduced as 0/1 move game
vector<long long> L(n); //maximum sum non empty subarray ending at each position
for(int i = 0;i < n;i++){
L[i] = (i && L[i-1]>0 ? L[i-1] : 0ll) + a[i];
}
vector<long long> R(n); //maximum sum non empty subarray starting at each position
for(int i = n-1;i >= 0;i--){
R[i] = (i+1<n && R[i+1]>0 ? R[i+1] : 0ll) + a[i];
}
if(k == 0){
long long ans = *max_element(L.begin(),L.end());
cout << ans << "\n";
}
else{
long long ans = LONG_MIN;
for(int i = 0;i < n;i++){
ans = max(ans,L[i]+R[i]-a[i]+b[i]);
}
cout << ans << "\n";
}
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
How do you calculate the final score if goals of Alice and Bob were swapped?
2158D - Palindrome Flipping Idea & Solution: kingmessi and abc864197532
Instead of directly transforming $$$s$$$ into $$$t$$$, is it enough to know how to transform any string into an intermediate string?
If you know how to turn any string into $$$0^n$$$ in at most $$$n$$$ operations, how can you use that to transform $$$s$$$ into $$$t$$$ in at most $$$2n$$$ operations?
If there is at least one position $$$p$$$ with $$$s_p = s_{p+1}$$$. Can you grow a block of equal bits starting from $$$[p, p+1]$$$?
How do you ensure such a position $$$p$$$ in strictly alternating string after exactly one operation?
When trying to grow the block to the right (or left), what happens if the next bit is equal to the block's boundary bit?
What if it is different? Can you use flipping a palindromic block (all equal bits) to force the boundary to match the next bit?
#include<bits/stdc++.h>
using namespace std;
vector<array<int,2>> reduce(string &s){
int n = s.size();
vector<array<int,2>> op;
int p = -1; // position p such that two consecutive characters are same
for(int i = 0;i < n-1;i++){
if(s[i] == s[i+1])p = i;
}
if(p == -1){ // string is alternating
op.push_back({0,2}); // substring of first three character must be palindrome
s[0] ^= 1;s[1] ^= 1;
p = 2;
}
char value = s[p+1];
int L = p,R = p+1; // We maintain [L,R] such that all position in it have the same value
while(R+1 < n){
if(s[R+1] != value)op.push_back({L,R});
R++;value = s[R];
}
while(L){
if(s[L-1] != value)op.push_back({L,R});
L--;value = s[L];
}
if(value == '1')op.push_back({0,n-1}); // We want to make all zeroes
return op;
}
void solve(){
int n;
cin >> n;
string s,t;
cin >> s >> t;
auto operation_s = reduce(s); // operations to reduce s to all zeroes
auto operation_t = reduce(t); // operations to reduce t to all zeroes
reverse(operation_t.begin(),operation_t.end());
int moves = operation_s.size() + operation_t.size();
cout << moves << "\n";
for(auto &[x,y] : operation_s)cout << x+1 << " " << y+1 << "\n";
for(auto &[x,y] : operation_t)cout << x+1 << " " << y+1 << "\n";
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--){
solve();
}
}
2158E - Sink Idea & Solution: kingmessi
How would you solve the problem if every value in the grid was distinct?
When some cells have the same value, is it natural to treat a connected component of equal valued cells as a single group?
For such a group, how can you decide whether this entire group needs a hole?
After a single query (decreasing the value of one cell), can the beauty increase by more than 1?
How many groups from previous grid can stop needing a hole because they now have a strictly smaller neighbour?
How can you model the evolution of the grid as a graph, where edges reflect either adjacency in the grid or "time adjacency" between different versions of the same cell?
If a cell receives $$$k$$$ decreasing updates over all queries, can you model it as a chain of $$$k+1$$$ nodes (one per value over time)?
How does connecting each new node to the latest versions of its neighbours help you maintain connected components of equal values efficiently?
#include<bits/stdc++.h>
using namespace std;
const int N = 400005;
int parent[N],siz[N],important[N],val[N];
void make_set(int v,int x) {
parent[v] = v;siz[v] = 1;important[v] = 1;val[v] = x;
}
int find_set(int v) {
if (v == parent[v])return v;
return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
a = find_set(a);
b = find_set(b);
if (a != b) {
if (siz[a] < siz[b])swap(a, b);
parent[b] = a;
siz[a] += siz[b];
important[a] = min(important[a],important[b]);
}
}
int n,m;
vector<array<int,2>> neighbours(int r,int c){
vector<array<int,2>> v;
if(r)v.push_back({r-1,c});
if(r+1 < n)v.push_back({r+1,c});
if(c)v.push_back({r,c-1});
if(c+1 < m)v.push_back({r,c+1});
return v;
}
void solve()
{
cin >> n >> m;
vector<vector<int>> a(n,vector<int>(m)); // latest value of a given cell
vector<vector<int>> ls(n,vector<int>(m)); // latest node created for a given cell
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
cin >> a[i][j];
ls[i][j] = m*i+j;
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
make_set(m*i+j,a[i][j]);
for(auto &[p,q] : neighbours(i,j)){
if(a[p][q] < a[i][j])important[m*i+j] = 0;
}
}
}
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
for(auto &[p,q] : neighbours(i,j)){
if(a[p][q] == a[i][j])union_sets(m*i+j,m*p+q);
}
}
}
int ans = 0;
for(int i = 0;i < n;i++){
for(int j = 0;j < m;j++){
if(parent[m*i+j] == m*i+j)ans+=important[m*i+j];
}
}
cout << ans << "\n";
int q;
cin >> q;
int nd = n*m;
for(int i = 0;i < q;i++){
int r,c,x;
cin >> r >> c >> x;
r--;c--;
x = a[r][c] - x;
set<int> s;
int mn = INT_MAX;
for(auto &[p,q] : neighbours(r,c)){
s.insert(find_set(ls[p][q]));
mn = min(mn,a[p][q]);
}
s.insert(find_set(ls[r][c]));
for(auto &y : s){
ans -= important[y];
}
for(auto &y : s){
if(val[y] > x)important[y] = 0;
}
make_set(nd,x);
if(mn < x)important[nd] = 0;
else important[nd] = 1;
for(auto &y : s){
if(val[y] == x){
union_sets(y,nd);
}
}
a[r][c] = x;
ls[r][c] = nd++;
s.clear();
for(auto &[p,q] : neighbours(r,c)){
s.insert(find_set(ls[p][q]));
}
s.insert(find_set(ls[r][c]));
for(auto &y : s){
ans += important[y];
}
cout << ans << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin >> t;
while(t--)
solve();
return 0;
}
2158F2 - Distinct GCDs (Hard Version) Idea & Solution: koderkushy
from copy import deepcopy
def get_nums(k: int=10):
nums = [
2**(i + j) * 3**i * 5**j * 7**(k-1-i) * 11**(k-1-j)
for i in range(k) for j in range(k)
]
return nums
def eulerian_paths(max_k: int = 100):
paths = [[], [0, 0], [1,1,0,0]]
for k in range(3, max_k + 1):
path = deepcopy(paths[k - 2])
x, y = k-2, k-1
if k % 2:
path.extend([x, x, y, y])
for j in range(1, x, 2):
path.extend([j, x, j+1, y])
path.append(0)
else:
path.extend([x, x, 1, y, y])
for j in range(2, x, 2):
path.extend([j, x, j+1, y])
path.append(0)
paths.append(path)
return paths
def path_len(k: int):
return 1 + (k*k+k)//2 - (0 if k%2 else k//2-1)
if __name__ == "__main__":
nums = get_nums(10)
paths = eulerian_paths(100)
for i in range(1, 101):
assert len(paths[i]) == path_len(i)
t = int(input())
for _ in range(t):
n = int(input())
l, r = 0, 100
while l < r-1:
m = r - (r-l)//2
if path_len(m) < n:
l = m
else:
r = m
path = paths[r]
assert len(path) >= n
a = [nums[i] for i in path[: n]]
print(*a)
#include "bits/stdc++.h"
using namespace std;
constexpr int64_t poww (int64_t a, int64_t p) {
assert(p >= 0);
int64_t res = 1;
while (p > 0) {
if (p & 1) res *= a;
a *= a, p >>= 1;
}
return res;
}
constexpr int32_t path_len(const int32_t n) {
return 1 + (n*n + n) / 2 - (n % 2 ? 0: n/2 - 1);
}
vector nums(0, 0ll);
vector walks(0, vector(0, 0));
void load_nums(const size_t p=10) {
nums.resize(p * p);
for (int i = 0; i < p; ++i)
for (int j = 0; j < p; ++j)
nums[i * 10 + j] = poww(2,(i+j)) * poww(3,i) * poww(5,j) * poww(7,(9-i)) * poww(11,(9-j));
}
void load_walks(const size_t max_k=100) {
walks.resize(max_k + 1);
walks[1] = vector({0, 0});
walks[2] = vector({1, 1, 0, 0});
for (int k = 3; k <= max_k; k++) {
auto& walk = walks[k];
walk = walks[k - 2];
const int x = k-2, y = k-1;
if (k % 2) {
walk.push_back(x);
walk.push_back(x);
walk.push_back(y);
walk.push_back(y);
for (int j = 1; j < x; j += 2)
walk.push_back(j),
walk.push_back(x),
walk.push_back(j+1),
walk.push_back(y);
walk.push_back(0);
} else {
walk.push_back(x);
walk.push_back(x);
walk.push_back(1);
walk.push_back(y);
walk.push_back(y);
for (int j = 2; j < x; j += 2)
walk.push_back(j),
walk.push_back(x),
walk.push_back(j+1),
walk.push_back(y);
walk.push_back(0);
}
}
}
void solve (const int kase) {
int n; cin >> n;
int l = 0, r = 100;
while (l < r - 1) {
int m = r - (r-l) / 2;
if (path_len(m) < n)
l = m;
else
r = m;
}
vector a(n, 0ll);
for (size_t i = 0; i < n; ++i) {
a[i] = nums[walks[r][i]];
cout << a[i] << ' ' ;
}
vector gcds(n-1, 0ll);
for (size_t i = 1; i < n; ++i) {
gcds[i-1] = gcd(a[i], a[i - 1]);
}
assert(set(gcds.begin(), gcds.end()).size() == n-1);
cout << '\n';
}
int main () {
ios_base::sync_with_stdio(0), cin.tie(0);
load_nums();
load_walks();
for (size_t i = 1 ; i < 101; ++i)
assert(walks[i].size() == path_len(i));
int t; cin >> t, assert(t >= 0);
for (int i = 0; t--; )
solve(++i);
}








Auto comment: topic has been updated by koderkushy (previous revision, new revision, compare).
Why no test cases in D with output = -1 ? Many codes could be hacked !! Like
Input:
1
2
01
10
Output:
-1
n > 3
Oh silly me ... Not seen ... thanx buddy
what an amazing solution for problem D!
Thanks!
For problem F2, it may be easier to randomize set X instead of using a formula. It's enough to take the first 21 prime numbers and multiply 11 random ones among them: 351258817
For anyone who needs just an add-on to understand the editorial for B a little better
I really got cooked by this problem but finally came up with a solution that happened to match the editorial 2 hrs post contest lol
-> Split (my brain into 2 ;-;)
odd freq numbers will always add exactly one to our ans, so treat them as fillers to make sequence of size 'n'
For even frequency numbers there are two cases
let f be such a freq (f is even) Case: 1 f / 2 is odd then in this case we can safely put f / 2 into each sequence and add 2 to the ans.
Case 2: f / 2 is even (i.e f is a multiple of 4) then the split with the minimal difference we can do is f / 2 — 1, f / 2 + 1 for eg if f = 8, f / 2 = 4, but if we put f / 2 occurences in each seq that wont add anything to our score
Instead if we put 3 , 5, then we can still add 2 to our ans.
But this will create a size diff of 2 in p & q. Suppose we put 3 in p and 5 in q
So to fix this, the next time we get f / 2 as even, we can put the extra 2 elements to p to balance it out again.
So it means, if we have an EVEN number of frequencies f such that f is a multiple of 4, then we can still always split all even freq and add 2 to the ans.
But if we have an odd number of such frequencies, then if we have atleast some odd frequencies to act as filler we are still good otherwise, exactly ONE of the even freq divisble by 4 will not contribute to the score at all and we dont add that.
code? btw easy explanation:)
What if we have an odd number of odd fillers? would the answer be 0 then because there is no way to balance it out? if it doesnt have to be 0 then could you pls provide a counterexample? tysm
odd numbers of odd would lead to a total sum of frequencies to odd number of elements , which is not possible because we have 2*n elements.
Oh wow thanks was wondering how to apply the 2n condition
Bro thanks I had been stuck at the tutorial for 2 hrs . Your approach saved me
You saved my brain
My solution for D is exactly similar to the editorial lol
Here, suppose there is a case where s -> t is not reached within 2n operaitons through the method talked in editorial. How are we sure that there would not exist any other set of operations that may lead s to t within 2n operations
My solution for C didn't pass because of +1 :(
For the last 30 minutes I was writing SEGMENT TREE OF ALL THINGS.
Quite sad, but it's alright because I absolutely LOVED the contest, thanks a lot for the good problems
When the question suggests outputting -1 for impossible case, but there isn't any in input example.

Funny joke, but it's problem, not question
I was referring only the output part, not the whole problem.
Wasn't sure what word to use, maybe "output suggests printing" might be clearer.
You can say, "the problem statement suggests". Anyways, your joke got a solid chuckle out of me lol. What's your native language if you don't mind me asking?
well, actually I'm not fond of disclosing information about myself to public forum.
fair enough
Yes lol in D no case with -1 .... though -1 would only appear in cases with n <= 2
if(n == 1 && s != t) cout << -1 << "\n"; else if(n == 2 && s != t && s == "01" || s == "10") cout << -1 << "\n";
A new node idea in E is quite amazing. Nice problem!
Got a new logic for Pb B without using mod 4 stuff. Check my solution here https://mirror.codeforces.com/contest/2158/submission/351225505 (It is not clean though, I was in a hurry to submit XD )
In C after the idea of differentiating between $$$k$$$ odd and even you can also just use Kadane's Algorithm: Maximum Subarray Problem.
See here 351210965. With even $$$k$$$ we just use Kadane's algorithm. With odd $$$k$$$ we add another state: The best possible sum, assuming we already used Alices one move to add $$$b_i$$$ to one number.
I use Kadane with k even and sparse table for k odd. ac
How did you use a sparse table lmao. Why did so many people overcomplicate C
Unrelated but why does your accepted submission for E contain
if (!(cin >> n >> m)) return;?Because he is a cheater ofc
In my country (VietNam), this code is similar LMM's. I thk Codeforces might automatically block it
delete_comment
cheat E , overkill C
you could treat k even with Kadane and k odd with 2 cases-
1) If every element is less than 0, then the answer is simply max(a[i]+b[i]) over all is
2) else you can write a dp[i][0]-> b already chosen, dp[i][1] -> b not chosen and then
dp[i][1]=max(max(dp[i-1][1]+a[i],0),max(dp[i-1][0]+a[i]+b[i],0)); dp[i][0]=max(dp[i-1][0]+a[i],0);
inspire purely by Kadane's algorithm
This I used kadane's algo with a bit of the editorial implementation. Very nice question
can someone tell the issue in my code
351260725
You are assuming that the answer for the 'odd k' cases will lie in the subarray which includes the subarray found using kadane's algorithm, but this is not necessarily true. Below is one of the cases when this would fail.
The answer that your solution would give is 6 (includes the 0th index only) while the actual solution is 7 (the subarray from 2nd to 3rd index along with b[3]).
thank u bro
-106
-104
In Problem F2, I wrote a randomization program and found 100 numbers with pairwise distinct gcd values.
randomization program
The probability of this randomization program succeeding was low, but I was lucky enough to stumble upon one such set of numbers.
After obtaining these 100 numbers, the construction method for this problem is the same as in CF1981D.
The submission
Can anyone tell me the problem with my code for D?:
Did you really just put your wrong code into an LLM and forgot to delete the comments? 351234958 351235693
Also I don't think an expert needs comments for fixing long long to int
Feels like Gemini code lol
Problem D can also solve through bfs .
Solution from editorial looks complicated. Alternate solutions are easier to come up to, though probably a bit harder to implement.
You already mentioned the BFS, I want to add that brute force is also possible.
So, we move from left to right, transforming current element of s into t, until 4 elements are left (4 is a guess, coming from fact that n is >= 4 by problem statement).
It can be done greedily. Say, current element of s is 1 and in t it's 0. Let's find next closest 1 in s. Interval between current element and that next 1 will be palindrome (because there are 1's on sides and all 0's in the middle). If there are no more 1's in s, it means all elements to the right are 0's, so flip them all since they form a palindrome, now we have all 1's, so flip again to get all 0's.
Thus, in at most 2 * (n — 4) operations we transform first n — 4 elements.
For the remaining 4 elements use either bruteforce of BFS. There are only 2^4 * 2^4 combinations, so we can just try all of them and make sure that all can be done withing 8 operations.
how did you calculated that " There are only 2^4 * 2^4 combinations ".
There are 2 ^ 4 binary strings with 4 elements, because each element has 2 possible values (0 and 1). We have 2 binary strings containing 4 elements each, thus for each of 2^4 possible values of 1st string, there 2^4 combinations of the second string. Or we can view 2 strings of lenght 4 as a 1 string of length for. Thus we have 2^8, which is equal to 2^4 * 2^4.
How does solution for D ensure that we're doing it in minimum operations?
The problem does not ask you to minimise the number of operations.
Yeah my bad :(
Did any one write recursive dp solution to problem C?
Here is a version
i think it is overcomplicate . but W for dp
Not recursive, but DP: https://mirror.codeforces.com/contest/2158/submission/351202309 State is 0 or 1. 0 — Alice didn't move, 1 — Alice did move.
the question C's solution is wrong because for this test case:
1 3 3 2 -7 3 1 -10 3
alice will not add -10 but subtract it so with your solution the final array is 2 -7 6 ans: 6 but the answer should be 2 3 3 ans: 8 i think you should update it and if can update the solution of this question @kingmessi
In question it's given that $$$b_i\geq0$$$.
oh yeah my bad
Is the solution given in the editorial for problem C is correct ??
Because if I have
n=1,k=1 means just 1 move and 1 size array made by Alice only
and if the array is
a={1}, b={-4}
if i am using the editorial solution it is giving me output -3 but it should be 5 naa i think because we can do either a[i]=a[i]-b[i] or a[i]=a[i]+b[i] so whyy can't we do here a[i]-b[i] in editorial it is always doing +b[i]
or i am incorrect thing is some other direction can any one please help and tell me the reason
In constraints it's given : $$$b_i \gt = 0$$$, so, $$$b$$$ can't have -ve values
ohoo i got it sorry for the inconvinence caused broo
Can anyone please tell me why this solution is not working ?
My Submisson
I have used the same concept similar to editorial 1 kadane's algo logic but is failing i have also added proper comments there can anyone please tell me why it is falling it will be very helpful for me
D: Repeat: flip the substring from the first
1to the next1.When there is only one
1left, it can be zeroed out in at most 3 flips.your sol was wayyy easier to understand,its so cool wtf,tysm for sharing,btw it can be zeroed out in just 2 flips dont need 3
simpler method to get "11..."
Why no test cases in D with output = -1 ? Many codes could be hacked !! Like
Input:
1
2
01
10
Output:
-1
Always read the statement and constraints carefully!! There's no -1!!
There is a statement which says if not possible to make output -1 ... But I didn't see n >= 3 for which always possible !
$$$4 \lt = n \lt = 100$$$ ...
Yepp got it
Why kids are downvoting .... I asked genuine doubt .. wth !!
https://mirror.codeforces.com/contest/2158/submission/351409705 why this fails can anybody give testcase?
By setting
curr = a[i] + b[i], you already ensure that atleast one element is taken which allows empty left and right subarrays. So changecurr += left[i - 1]tocurr += max(0LL, left[i - 1]. Make similar change to the next line of your code.got it thankyou
What an amazing question f2. My blog https://mirror.codeforces.com/blog/entry/148841 contains a proof-style explanation of F2, which may be helpful if you like formal proofs :)
What would be the expected rating of D?
is the checker in problem D wrong? cause in test 1 even when my code print valid operations, the checker log still is "wrong answer Invalid operation: substring is not a palindrome (test case 1)", could anyone check the code for me? here is my code 351716981
bc the substring is not pal ? 2-3 = 01 is not valid'
oh yeah mb for some reasons i thought a string with 2 characters is always a palindrome
like the solution to B
Wow!Amazing problemn for D!
Solution for D — wow!
Nowadays B is getting more hard and hard right?
Question B is great! I totally get it now.
really great editorial
Third problem can be more complex if u just add -1e6<=bi<=1e6
D was so good. i feel proud of myself that i could come up with the same solution given in the editorial. (though it took me half an hour to think and another half to code :))
Could someone please explain why in C we need to do L[i] + R[i] + a[i] + b[i]? Why do we calculate max subarray sums for either sides of i?