Maximum money|Coding Problem

Input:
N = 5 , K = 10
Output:
30
Explanation:
The Robber can rob from the first, third
and fifth houses which will result in 30.
Input:
N = 2 , K = 12
Output:
12
Explanation:
The Robber can only rob from the first
or second which will result in 12.
/* author : @akash */#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mod 1000000007
#define ld long double
class Solution
{
public:
void solve()
{
int n;
int k;
cin>>n>>k;
int ans;
if(n%2==0)
{
ans=n/2;
}
else
{
ans=n/2+1;
}
cout<<ans*k;
}
};
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t;
cin>>t;
while(t--)
{
Solution ob;
ob.solve();
cout<<"\n";
}
return 0;
}
// time complexity : T(n)=O(1)
// space compexity : S(n)=O(1)

--

--

--

Student of Computer Science & Engineering at Moradabad Institute of Technology.

Love podcasts or audiobooks? Learn on the go with our new app.

Networking for the Software Engineer: Connectivity

How do you stack up?

Scripting and Automation Skills for DevOps Engineers

The journey I think every young programmer should take — My experience with GCI

MySkill — Python for Data Science

Tezos Blockchain cycle 415 stats

SQL unit testing with Redgate and tSQLt

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Akash Kumar

Akash Kumar

Student of Computer Science & Engineering at Moradabad Institute of Technology.

More from Medium

The SOLID Principles of Object-Oriented Programming and NoSQL

Choosing between self-learning, Bootcamp or College

Vite.js

Importance of beauty in architecture.