Radio-frequency identification (RFID) useselectromagnetic fields to automatically identify andtrack tags attached to objects. With RFID, we canmanage items in wareho use easily and efficiently.Instead of checking each item manually withtraditionally methods, such as barcode or QR code, wecan use an RFID scanner to automatically detect theIDs of all items in a warehouse.Intelligent Corporation of Production and Commerce(ICPC) has a sequence of N warehouses, organized as a row in HiTech Park. The ith warehousecontains wi items.ICPC intends to re-organize all items in warehouses so that ICPC can have available space forits new business. As each item is attached an RFID tag, there is no need to manually check outan item from a warehouse or check in an item to a new warehouse.A robot is used to move all items from a warehouse to either its previous or next adjacentwarehouse. Only when that warehouse is empty can a robot begin its task to empty anotherwarehouse. On average, it takes 1 second to move 1 item from a warehouse to its adjacentwarehouse.Compute the minimum time required to move items between warehouses so that finally atmost M warehouses contain items (other warehouses are all empty).InputThe first line of input contains two integers N and M, separated by a space. (1 ≤ N ≤ 1500, 1 ≤M ≤ 100)The second line contains N positive integers that are the number of items in each warehouse.The number of item in a warehouse is no more than 210. Initially, there is no empty warehouse.OutputDisplay a single positive integer that is the minimum time required (in seconds) so that at mostM warehouses contain items.
đang được dịch, vui lòng đợi..