You are a senior chemist working in a cutting-edge molecular research laboratory.
Your team has developed a revolutionary molecular reactor that can synthesize complex compounds through a series of controlled chemical reactions.
The reactor operates on a strict schedule where each synthesis reaction requires exactly 5 minutes to complete.
The laboratory receives research samples at various times throughout the day, and each sample must undergo a synthesis reaction in the molecular reactor.
However, there's a critical limitation: the reactor can only process one sample at a time and samples waiting to be processed are stored in a specialized cooling chamber.
If the cooling chamber contains more than 10 samples, any newly arriving samples will be rejected due to stability concerns.
Your task is to determine the total time required to process all accepted samples through the molecular reactor.
The output should be the time in seconds since the start of the laboratory's operating day.
Notes:
- The cooling chamber capacity is calculated by the number of samples waiting to start synthesis, not including the sample currently being processed in the reactor.
- If a new sample arrives at the same moment as when another sample completes its synthesis, the first sample waiting in the cooling chamber starts synthesis first.
Example
For times = [1, 6, 9, 502], the output should be 1201.
For times = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15], the output should be 3601.
Input/Output
[execution time limit] 0.5 seconds (cpp)[memory limit] 1 GB[input] array.integer times
An array of distinct integers representing arrival times (seconds since the start of the laboratory's operating day). It is guaranteed that all the arrival times are given in increasing order.
Guaranteed constraints:
times.lengthis at least 1- The reactor processes one sample at a time
- The reactor takes 300 seconds to process each sample
这道 Visa OA 题本质上是一个“单机排队 + 容量限制 + 事件模拟”问题:按时间顺序处理每个样本到达事件,并维护一个 FIFO 队列表示冷却室中等待加工的样本。每次要同时考虑两类事件——样本到达与当前样本完成;当处理器空闲时,队首样本立即开始 300 秒的合成。关键细节在于容量只统计“等待队列”中的样本数,不包含正在反应的样本,而且当到达时间与完成时间相同,应优先让队列中最早等待的样本先开始。实现上通常用队列进行模拟,结合当前时间指针推进,整体复杂度可做到 O(n)。