cswork / OA打开练习工作台

RubrikOA #15

Get Minimum Operations

估计中等评测数据准备中,可先阅读题面

考点(AI 标注)二分查找贪心调度

Given two arrays change and arr that consist of n and m integers respectively. In the ith operation, one of the two operations can be performed: you can choose to decrement any element of arr by 1 or do nothing. if change[i] > 0 and arr[change[i]] = 0, it can be changed to NULL. Assume indexing starts from 1, find the minimum number of operations required to change all the elements of the array to NULL or report -1 if it is not possible. Function Description Complete the function getMinOperations in the editor below. getMinOperations has the following parameter(s):

  • int change[n]: an array of integers
  • int arr[m]: an array of integers Returns int: the minimum number of operations required to change all the elements to NULL, or -1 if it is not possible

Constraints

:o