Amazon Question - 1 Maximum money

Given street of houses (a row of houses), each house having some amount of money kept inside; now there is a thief who is going to steal this money but he has a constraint/rule that he cannot steal/rob two adjacent houses. Find the maximum money he can rob.
Input:
The first line of input contains an integer T denoting the number of test cases.
The first line of each test case is N and money.
Output:
Print maximum money he can rob.
Constraints:
1 ≤ T ≤ 100
1 ≤ money ≤ 100
1 ≤ N ≤ 1000

Example:
Input:
2
5 10
2 12
Output:
30
12



Code in C-Language
#include<stdio.h>
int main()
{
int n;
int house, money;
scanf("%d", &n);
while (n > 0){
scanf("%d %d", &house, &money);
if (house % 2 == 1)
house++;
printf("%d\n", money*house/2); 
n--;
}
return 0;
}

Comments

Popular posts from this blog

C Program to Print a trapezium pattern

C Program to Print Pattern 1*2*3*4 9*10*11*12 13*14*15*16 5*6*7*8

Glimpse Of SPYDER | Mahesh Babu | A R Murugadoss | Rakul Preet Singh | Harris Jayaraj | #SPYDER Trailer , Teaser