When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
9 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
what output?
#include <vector>
#include <iostream>
#include <algorithm>
#include <climits>
using namespace std;
int delta;
int calculate(const vector<int> &arrival, int amount, int firstLaunch)
{
int totalWaitTime = 0;
int nextLaunch = firstLaunch;
size_t idx = 0;
for (int i = 0; i < amount; ++i)
{
// Move to the first arrival time that is not less than the next launch time
while (idx < arrival.size() && arrival[idx] < nextLaunch)
{
++idx;
}
if (idx < arrival.size())
{
// Calculate the wait time for this launch
totalWaitTime += max(0, nextLaunch - arrival[idx]);
// Move to the next arrival time after this launch
idx++;
}
// Prepare for the next launch
nextLaunch += delta;
}
return totalWaitTime;
}
int findMinWaitTimeBeforeFirstArrival(const vector<int> &arrival, int amount)
{
int minTime = INT_MAX;
for (int launchTime = 0; launchTime < arrival[0]; ++launchTime)
{
int currentTime = calculate(arrival, amount, launchTime);
cout << "findMinWaitTimeBeforeFirstArrival - Launch Time: " << launchTime << ", Wait Time: " << currentTime << endl;
minTime = min(minTime, currentTime);
}
return minTime;
}
int findMinWaitTimeBetweenArrivals(const vector<int> &arrival, int amount)
{
int minTime = INT_MAX;
for (size_t i = 0; i < arrival.size() - 1; ++i)
{
for (int launchTime = arrival[i]; launchTime < arrival[i + 1]; ++launchTime)
{
int currentTime = calculate(arrival, amount, launchTime);
cout << "findMinWaitTimeBetweenArrivals - Launch Time: " << launchTime << ", Wait Time: " << currentTime << endl;
minTime = min(minTime, currentTime);
}
}
return minTime;
}
have you stepped trough your code with the debugger yet?
i don't know how to use it
then high time to learn it
i tried to add some cout sentences to watch the value of the variable but they all are 0
time to step trough the code with an debugger
ok i will try