You are on page 1of 3

S2 BTech

C Programming
Code-Chef Submission

Name: ANANDHA KRISHNAN. R


Roll No: AM.EN.U4ECE17109

QUESTION: 3: ROWCOLOP
EASY
You are given an N × N grid initially filled by zeros. Let the rows and
columns of the grid be numbered from 1 to N, inclusive. There are
two types of operations can be applied to the grid:

RowAdd R X: all numbers in the row R should be increased by X.


ColAdd C X: all numbers in the column C should be increased by X.
Now after performing the sequence of such operations you need to
find the maximum element in the grid.
//ANANDHA KRISHNAN.R
# include <stdio.h>
int main()
{
int n,k,row,s1,i;
char a[6];
scanf("%d%d",&n,&k);
int r[n];
int c[n];
int rmax=0,cmax=0;
for(i=1;i<=n;i++)
{
r[i]=0;
c[i]=0;
}
while(k--)
{
scanf("%s",a);
scanf("%d",&row);
scanf("%d",&s1);
if(a[0]=='R')
{
r[row]=r[row]+s1;
if(rmax<r[row])
rmax=r[row];
}
else if(a[0]=='C')
{
c[row]=c[row]+s1;
if(cmax<c[row])
cmax=c[row];
}
}
printf("%d\n",rmax+cmax);
return 0;
}
APPROACH:

You might also like