#abc325f. F - Sensor Optimization Dilemma

F - Sensor Optimization Dilemma

Score : 500500 points

问题描述

作为Keyence工厂的经理,你希望监控传送带上的几个区域。共有NN个区域需要监控,其中第ii个区域的长度为DiD_i米。

有两种类型的传感器可供选择,以下是关于每种传感器的一些信息。

  • 类型-jj传感器 (1j2)(1\leq j \leq 2):可以监控长度为LjL_j米的区域。每个传感器的价格为CjC_j元,并且总共最多可以使用KjK_j个此类传感器。

你可以将一个区域划分为多个子区域进行监控。如果传感器监控的区域重叠,或者它们监控的长度超过你想要监控的区域长度,这都是可以接受的。例如,当L1=4L_1=4L2=2L_2=2时,你可以使用一个类型-11的传感器监控长度为3米的区域,或者使用一个类型-11和一个类型-22的传感器共同监控长度为5米的区域。

确定是否可能监控所有NN个区域,并在可能的情况下,找出所需传感器的最小总成本。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

As the factory manager of Keyence, you want to monitor several sections on a conveyor belt. There are a total of NN sections you want to monitor, and the length of the ii-th section is DiD_i meters.

There are two types of sensors to choose from, and below is some information about each sensor.

  • Type-jj sensor (1j2)(1\leq j \leq 2): Can monitor a section of length LjL_j meters. The price is CjC_j per sensor, and you can use at most KjK_j sensors of this type in total.

You can divide one section into several sections for monitoring. It is fine if the sections monitored by the sensors overlap, or if they monitor more than the length of the section you want to monitor. For example, when L1=4L_1=4 and L2=2L_2=2, you can use one type-11 sensor to monitor a section of length 33 meters, or use one type-11 and one type-22 sensor to monitor a section of length 55 meters.

Determine whether it is possible to monitor all NN sections, and if it is possible, find the minimum total cost of the necessary sensors.

Constraints

  • 1N1001\leq N \leq 100
  • 1Di,Lj1051\leq D_i,L_j \leq 10^5
  • 1Cj1091\leq C_j \leq 10^9
  • 1Kj1031\leq K_j \leq 10^3
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN

D1D_1 D2D_2 \dots DND_N

L1L_1 C1C_1 K1K_1

L2L_2 C2C_2 K2K_2

Output

If it is impossible to monitor all NN sections, print -1. Otherwise, print the minimum total cost of the necessary sensors.

Sample Input 1

3
3 5 10
4 3 3
2 2 6

Sample Output 1

17

You can monitor all sections by using three type-11 sensors and four type-22 sensors as follows.

  • Use one type-11 sensor to monitor the first section.
  • Use one type-11 and one type-22 sensor to monitor the second section.
  • Use one type-11 and three type-22 sensors to monitor the third section.

In this case, the total cost of the necessary sensors is 3×3+2×4=173\times 3 + 2\times 4 = 17, which is the minimum.

Sample Input 2

3
3 5 10
4 3 3
2 2 3

Sample Output 2

-1

Sample Input 3

2
4 8
3 1 100
4 10000 100

Sample Output 3

5

It is fine if one type of sensor is not used at all.

update @ 2024/3/10 01:48:36