describe the problem and your solution (¿did you understand the question correctly? ¿is your approach properly implemented?)
and if you can, the input/output that fails.
It looks like Java. The C++ signature is more like:
staticint minuteToWinIt(vector<int> a , int k);
Paraphrasing the question:
You are given integers n and k and then an array of n integers. You need to output the minimum number of changes to the elements that will make a[i+1] - a[i] == k true for all i from 0 to n-2.
E.g., 5 2
1 3 4 7 10
Changing 4 to 5 and 10 to 9 gives: 1 3 5 7 9
which are all k == 2 apart.
Since we had to change 2 elements, the output should be 2.
@tpb, @ne555
can you code the problem in cpp for full marks
i got only 16 marks out of 20.
the cpp signature is-:
// Complete the minuteToWinIt function below.
int minuteToWinIt(vector<int> a, int k) {
// Return the minimum amount of time in minutes.
that's the new question, please help to code the below problem-:
------A Time-saving Affair------
Janet is in an Uber on her way to an interview. The driver promises to take her to the venue as soon as possible. The driver is aware
that:-
-There are 'n' junctions in the city of Mumbai, numbered from '1' to 'n'.
-Janet's interview location is at junction 'n'. They are initially at junction '1'.
-There are 'm' bidirectional roads connecting some pairs of junctions, each one requiring some amount of time to pass through it.
At every junction, there are traffic lights denoting whether they are allowed to go further or to wait. Traffic lights have two colors,
'red' and 'green'. The driver can commute through junctions based on these conditions:
1. At any junction, if the traffic signal's light is green, then they can go immediately, otherwise, they have to wait until traffic signal
becomes green.
2. Traffic signal changes its color every 'k' seconds of time at all junctions simultaneously.
Initially, at the '0th' second, all traffic lights have changed to green color at all the junctions. If the cab driver reaches a junction at a second when the traffic light changes its color, then he sees the traffic light after the change.
Can you help the driver determine the least amount of time needed to reach the interview location?
Complete the function leastTimeToInterview which takes in three integers n,k and m and returns the least amount of time
needed to reach the interview location, in seconds. You need to take the information about the roads from the standard input. They
will be specified in 'm' lines, as described in the input format section below.
Input Format:-
-The first line contains an integer 'n', the number of junctions.
-The second line contains an integer 'k' denoting the time taken by a signal to change its color.
-The third line contains an integer 'm' denoting the number of roads.
-The next 'm' lines describe the roads. Each consist of three space-separated integers 'i','j' and 't' where 'i' and 'j' denotes a road between two junctions and 't' denotes time required to travel through it.
Constraints-:
- 1<= n <= pow(10,4)
- 1<= k <= pow(10,2)
- 1<= m <= pow(10,5)
- 1<= i,j <= n
- 1<= t <= pow(10,3)
- There can be self-loops, i.e., roads connecting the same pair of junctions.
- There is at least one path from junction '1' to junction 'n'.
Output Format-:
Print a single integer denoting the shortest amount of time required to reach junction 'n'.
- Junction number 1: The cab driver can visit any of the adjacent junctions. He chooses to visit junction 2. Since the traffic signal is
'green' at the '0th' second, He can visit junction 2 which takes 3 seconds.
- Junction number 2: The traffic signal is still 'green' since traffic signals change color every '4' seconds. The cab driver now chooses
to visit junction '3' which takes '1' second, and we are now at the '4th' second.
- Junction number 3: 4 seconds have passed, and the traffic signal has already become 'red'. They have to wait for 4 more seconds
until the signal again becomes 'green'.
- Junction number 5: The cab takes the route to junction 5 which takes 1 second. So far, 9 seconds have passed.
- Junction number 7: The traffic signal is still 'green' and the cab can go to junction 7. It takes 2 seconds to reach junction 7.
In total, it takes 11 seconds to go from junction 1 to junction 7 . It can be shown that this is the minimum amount of time possible.
#include <bits/stdc++.h>
using namespace std;
// Complete the leastTimeToInterview function below.
long leastTimeToInterview(int n, int k, int m) {
// Return the least amount of time needed to reach the interview location in seconds.
}
int main()
{
ofstream fout(getenv("OUTPUT_PATH"));
int n;
cin >> n;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int k;
cin >> k;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
int m;
cin >> m;
cin.ignore(numeric_limits<streamsize>::max(), '\n');
long result = leastTimeToInterview(n, k, m);
fout << result << "\n";
fout.close();
return 0;
}