Problem Description:
Nesamani wants to paint a beautiful picture on a building that is M sections long. Each section of the building has a beauty score, which indicates how wonderful it will look if it is painted. Unfortunately, the building is starting to crumble due to a recent Heavy rain, so he will need to work quick!
At the beginning of each day, Nesamani will paint one of the sections of the building. On the first day, he is free to paint any section he likes. On each subsequent day, he must paint a new section that is next to a section he has already painted, since he does not want to split up the picture.
#include<stdio.h>
#include<stdlib.h>
char *hack="vector<int> b(N+1);";
int main(){
int T,k;scanf("%d",&T);
for(k=1;k<=T;++k){
int N,i;scanf("%d",&N);
char s[105];scanf("%s",s);
int len=(N+1)/2,sum=0,max=0;
for(i=0;i<len;i++)sum+=s[i]-'0';
max=sum;
for(i=len;i<N;i++){
sum+=s[i]-'0';
sum-=s[i-len]-'0';
max=(max+sum+abs(max-sum))/2;}
printf("%d\n",max);}
}
0 Comments