21691_E-bookZealo

2022-5-16 18:20| 发布者: Hocassian| 查看: 27| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505764132700-Problem List-采集的数据-后羿采集器.html

Pro.ID

21691

Title

E-book Zealot

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21691

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/32768 K (Java/Others)
  • 描述

    Association for Cost Minimum (ACM) is a non-profit organization which is engaged in helping people to save resource and money. Now, ACM wants to develop a kind of software to help so-called e-Book zealot to save money.

    The e-Book zealot enjoys reading book on-line very much; sometimes he reads more than 10 books a day, nobody knows how long he sleeps a day. The e-Books are not free of charge. In fact, they're not cheap. From Figure1, ACM knows that how many books the zealot has read.

    Figure 1

    The zealot read only 1 book on day1 and read 5 books on day3. And from figure2, ACM knows the cost of reading one e-Book. Unfortunately, the cost varies instead of being constant.

    Figure 2

    The cost of Day1 and Day2 is 5 per e-Book, and it changed to 1 per e-Book on Day3, and it changed to 2 per e-Book on Day5. Therefore, the zealot should pay  to the e-Book provider for the 9 books he read.

    In order to attract more people to read on-line, the e-Book provider promotes some set-menus. See the figure 3 below.

    Figure 3

    It means if the zealot chooses Set Menu A1, he will pay 6 for reading 2 consecutive books; and if he chooses Set Menu A2, he will pay 7 for reading 4 consecutive books. For example, if he pays the first 2 books by Set Menu A1, and pays the next 4 books by Set Menu A2, then pays the last 3 books without any set menus, he'll pay 6 + 7 + 1 + 1 + 2 = 17. In fact, if he pays the first 4 books by Set Menu A2, and pays last 5 without any set menus, he'll pay . Of course, the Set Menu can be used any times if necessary. And if necessary, the w-books Set Menu can use to pay q (0 < q < w) book(s); for example, the zealot can pay 7 for 3 continued books by Set Menu A2 (3 < 4).

    Further more, the e-Book provider promotes another kind of set-menus. In these set-menus, the provider doesn't care about the number of the books the zealot reads; he cares about how many days the zealot reads. See figure4.

    Figure 4

    It means that if the zealot chooses the Set Menu B1, he will pay 9 for reading any number books within 3 consecutive days; and if he chooses Set Menu B2, he will pay 12 for reading books of 4 continued days. For example, if he pays first 4 days reading by Set Menu B2, and pays last day reading without any set menus, he'll pay. Similarly, the set menus can be used any times. And the w-days Set Menu can use to pay q (0 < q < w) day(s) reading.

    Now, your task is to write a program to help the zealot. Help him to minimize the money he should pay according to the number of books he reads, the prices and the set menus.

    输入

    The input consists of several test cases. The first line of each test case contains only one integer n (0 < n ≤ 1,000), representing the number of days the zealot has read. The second line contains n non-negative integers d1, d2dn ( ∑di ≤ 10,000), representing the number of books the zealot read on Day 1, Day 2, …, Day n. The third line contains only one integer n1 (0 < n1 ≤ 1,000), representing the number of different price. Then n1 integer pairs follow in separated lines.

    c1  p1
    c2  p2
      …
    cn1  pn1

    (c1 = 1, c1 < c2 < … < cn1n,  p1, p2pn1 > 0)

    It means that at ci day, the price of reading one book changes to pi (0 < in1). In the next line, one integer n2 (0 ≤ n2 ≤ 1,000), representing the number of set menu A (Books Set Menus, see the figure 3). Then n2 integer pairs are in the following separated lines.

    a1  r1
    a2  r2
      …
    an2  rn2

    (0 < a1 < a2 < … < an2 ≤ 10,000,   r1, r2rn2 > 0)

    It means that the zealot can pay ri for reading ai (or less ai) consecutive books (0 < in2). Then one integer n3 (0 ≤ n3 ≤ 1,000) follows in then next line, representing the number of set menu B (Days Set Menus, see the figure 4). Then n3 integer pairs are in the following separated lines.

    b1  s1
    b2  s2
      …
    bn3  sn3

    (0 < b1 < b2 < … < bn3 ≤ 1,000,  s1, s2sn3 > 0)

    It means that the zealot can pay si for reading books of bi (or less bi) continued days (0 < in3  ).

    The input is terminated by a line with one zero.

    输出

    Description

    Association for Cost Minimum (ACM) is a non-profit organization which is engaged in helping people to save resource and money. Now, ACM wants to develop a kind of software to help so-called e-Book zealot to save money.

    The e-Book zealot enjoys reading book on-line very much; sometimes he reads more than 10 books a day, nobody knows how long he sleeps a day. The e-Books are not free of charge. In fact, they're not cheap. From Figure1, ACM knows that how many books the zealot has read.

    Figure 1

    The zealot read only 1 book on day1 and read 5 books on day3. And from figure2, ACM knows the cost of reading one e-Book. Unfortunately, the cost varies instead of being constant.

    Figure 2

    The cost of Day1 and Day2 is 5 per e-Book, and it changed to 1 per e-Book on Day3, and it changed to 2 per e-Book on Day5. Therefore, the zealot should pay  to the e-Book provider for the 9 books he read.

    In order to attract more people to read on-line, the e-Book provider promotes some set-menus. See the figure 3 below.

    Figure 3

    It means if the zealot chooses Set Menu A1, he will pay 6 for reading 2 consecutive books; and if he chooses Set Menu A2, he will pay 7 for reading 4 consecutive books. For example, if he pays the first 2 books by Set Menu A1, and pays the next 4 books by Set Menu A2, then pays the last 3 books without any set menus, he'll pay 6 + 7 + 1 + 1 + 2 = 17. In fact, if he pays the first 4 books by Set Menu A2, and pays last 5 without any set menus, he'll pay . Of course, the Set Menu can be used any times if necessary. And if necessary, the w-books Set Menu can use to pay q (0 < q < w) book(s); for example, the zealot can pay 7 for 3 continued books by Set Menu A2 (3 < 4).

    Further more, the e-Book provider promotes another kind of set-menus. In these set-menus, the provider doesn't care about the number of the books the zealot reads; he cares about how many days the zealot reads. See figure4.

    Figure 4

    It means that if the zealot chooses the Set Menu B1, he will pay 9 for reading any number books within 3 consecutive days; and if he chooses Set Menu B2, he will pay 12 for reading books of 4 continued days. For example, if he pays first 4 days reading by Set Menu B2, and pays last day reading without any set menus, he'll pay. Similarly, the set menus can be used any times. And the w-days Set Menu can use to pay q (0 < q < w) day(s) reading.

    Now, your task is to write a program to help the zealot. Help him to minimize the money he should pay according to the number of books he reads, the prices and the set menus.

    Input

    The input consists of several test cases. The first line of each test case contains only one integer n (0 < n ≤ 1,000), representing the number of days the zealot has read. The second line contains n non-negative integers d1, d2dn ( ∑di ≤ 10,000), representing the number of books the zealot read on Day 1, Day 2, …, Day n. The third line contains only one integer n1 (0 < n1 ≤ 1,000), representing the number of different price. Then n1 integer pairs follow in separated lines.

    c1  p1
    c2  p2
      …
    cn1  pn1

    (c1 = 1, c1 < c2 < … < cn1n,  p1, p2pn1 > 0)

    It means that at ci day, the price of reading one book changes to pi (0 < in1). In the next line, one integer n2 (0 ≤ n2 ≤ 1,000), representing the number of set menu A (Books Set Menus, see the figure 3). Then n2 integer pairs are in the following separated lines.

    a1  r1
    a2  r2
      …
    an2  rn2

    (0 < a1 < a2 < … < an2 ≤ 10,000,   r1, r2rn2 > 0)

    It means that the zealot can pay ri for reading ai (or less ai) consecutive books (0 < in2). Then one integer n3 (0 ≤ n3 ≤ 1,000) follows in then next line, representing the number of set menu B (Days Set Menus, see the figure 4). Then n3 integer pairs are in the following separated lines.

    b1  s1
    b2  s2
      …
    bn3  sn3

    (0 < b1 < b2 < … < bn3 ≤ 1,000,  s1, s2sn3 > 0)

    It means that the zealot can pay si for reading books of bi (or less bi) continued days (0 < in3  ).

    The input is terminated by a line with one zero.

    Output

    For each test case, output only one single line contains the least money the zealot should pay.

    Sample Input

    5
    1 1 5 1 1
    3
    1 5
    3 1
    5 2
    2
    2 6
    4 7
    2
    3 9
    4 12
    0

    Sample Output

    12

    Source

    样例输入

    5
    1 1 5 1 1
    3
    1 5
    3 1
    5 2
    2
    2 6
    4 7
    2
    3 9
    4 12
    0

    样例输出

    12

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部