Given N, number of steps in stairs and W, the width of steps, you have to calculate the total length of carpet needed to cover the stairs.
Also, the width of each step is same W but the height is given by:
1. Y[x] = 2*x, if height of the step is 1
2. Y[x] = Y[x-1] + 1, if height of the step is 2
#include <stdio.h> int main() { int t; scanf("%d",&t); while(t--) { unsigned long long int w,n,i,a,out=0; scanf("%llu %llu",&w,&n); for(int i=1;i<=n;i++) { scanf("%llu",&a); if(a==1) out=2*i; else if(a==2) out=out+1; } printf("%llu\n",(out+n*w)); } return 0; }
Input:
First line - Number of test cases
Second line - (W) width of steps and (N) number of steps
Third line - N seperated integers A[1], A[2]...., A[N]
Output:
The total length of the carpet.
The total length of the carpet.
Sample Input:
4
2 2
1 1
2 2
2 2
2 2
1 2
2 2
2 1
Sample Output:
8
6
7
8