Question: I wrote the following code to attempt to solve it but it's incorrect. However it does work for the two sample test cases provided in

 I wrote the following code to attempt to solve it but

I wrote the following code to attempt to solve it but it's incorrect. However it does work for the two sample test cases provided in the problem.

#include #include #include #include #include

using namespace std;

int main() { string line; getline(cin, line); stringstream ss(line); int numDays, price; ss >> numDays >> price;

int totalCost = 0; vector days(numDays); vector inBetween(numDays - 1);

getline(cin, line); ss = stringstream(line); for (int i = 0; i > days[i]; }

if (numDays == 1) { totalCost += price + 1; } else { totalCost += price + 1; for (int i = 0; i price + 1) { totalCost += price + 1; } else { totalCost += inBetween[i]; } } }

cout

Can you figure out the issue and write a corrected code?

1N105 ) days that she will watch Mooloo. Because Mooloo is a paid subscription service, she now needs to decide how to minimize the amount of money she needs to pay. Mooloo has an interesting subscription system: it costs d+K(1K109) moonies to subscribe to Mooloo for d consecutive days. You can start a subscription at any time, and you can start a new subscription as many times as you desire if your curren subscription expires. Given this, figure out the minimum amount of moonies Bessie needs to pay to fulfill her schedule. INPUT FORMAT (input arrives from the terminal / stdin): The first line contains integers N and K. The second line contains N integers describing the days Bessie will watch Mooloo: 1d1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!