← 返回 amazon 的题目列表CPU Credit Calculation
类型:online_judge
Write a program to calculate CPU Credit. Given the history of CPU usage and the maximum available CPU usage over an hour period, calculate the CPU Credit that the system gained or consumed during the given timeframe.
Input:
A list of usage rates, where each element represents an hourly CPU usage rate (integer, between 0 to 100).
Maximum available CPU usage (integer, between 0 to 100).
Output:
CPU Credit gained or consumed by the system (integer).
Example:
Input: usage = [20, 30, 50, 80], max_usage = 50 Output: 10
Explanation:
In the first two hours, the system didn’t use all available CPU, thus accumulating an extra 50 credits. In the following two hours, it consumed 40 credits, leaving 10 credits remaining.
Example
Input
20 30 50 80
50