# Contest : Carnival Finale Coding Competition | CodeChef

Author: Codechef Adgitm Chapter : naqeeb2710 | CodeChef User Profile for NAQEEB AHMED | CodeChef Tester: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9
Editorialist: Codechef Adgitm Chapter : https://www.codechef.com/users/test_account_9

Easy

# PROBLEM:

A Man has an n number coin and you know the value of all the coins. You cannot change the order of the coin. There are m numbers of changes allowed and after each change, some value of the coin will update. Your task is to find out the maximum amount in these bunch of coins.

EXPLANATION:
Find maximum while traversing.

SOLUTION:
C++:

#include<bits/stdc++.h>

using namespace std;

int maxSubArraySum(int a[], int size)
{
int max_so_far = INT_MIN, max_ending_here = 0;

``````for (int i = 0; i < size; i++)
{
max_ending_here = max_ending_here + a[i];
if (max_so_far < max_ending_here)
max_so_far = max_ending_here;

if (max_ending_here < 0)
max_ending_here = 0;
}
return max_so_far;
``````

}

int main()
{
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<m;i++)
{
int k,x;
cin>>k>>x;
a[k-1]=x;
int z = sizeof(a)/sizeof(a[0]);
int max_sum = maxSubArraySum(a, z);
cout<<max_sum<<endl;
}
return 0;
}