链接:登录—专业IT笔试面试备考平台_牛客网
来源:牛客网
There're nn cheeses in the house. The ii-th cheese is between point ii and point i+1i+1. The ii-th cheese's size is aiaiand its weight is bibi.
房子里有 nn 奶酪。 ii -th奶酪介于点和点 ii i+1i+1 之间。 ii 奶酪的大小和 aiai 重量是 bibi 。
Nazrin is at point 11 in the beginning and wants to steal some cheeses. She has mm chances to take the cheeses:
纳兹林 11 一开始就想偷一些奶酪。她有机会 mm 拿奶酪:
In the ii-th time, Nazrin brings a bag of size sziszi. Since she's greedy, for i>1i>1, szi≥szi−1szi≥szi−1 always holds. She can travel from point 11 and take some cheeses. She can only travel from point xx to x+1x+1, or backwards. If she wants to travel from point xx to point x+1x+1, she has to dig a hole on the xx-th cheese or take it. She can't take a cheese with a hole on it. Of course, the sum of the cheeses' size she takes in the ii-th time can't be larger than sziszi. After taking the cheeses, she needs to go back to point 11.
在 ii -第一次,纳兹林带来了一个大小的 sziszi 袋子.既然她贪婪,因为 i>1i>1 , szi≥szi−1szi≥szi−1 永远持有。她可以从点 11 出发,拿一些奶酪。她只能从一个点到 x+1x+1 另一个点 xx 或向后移动。如果她想从一个点到另一个点 xx x+1x+1 旅行,她必须在奶酪上 xx 挖一个洞或拿走它。她不能拿一个有洞的奶酪。当然,她第-次吃 ii 的奶酪大小的总和不能大于 sziszi .吃完奶酪后,她需要回到点 11 。
Please maximize the sum of the weights of taken cheeses and output it.
请最大化所采奶酪的重量总和并输出它。
输入描述:
The first line contains two integer nn (1≤n≤2001≤n≤200) and mm (1≤m≤1051≤m≤105).
For the following nn lines, the ii-th line contains two integers aiai (1≤ai≤2001≤ai≤200) and bibi (1≤bi≤1051≤bi≤105).
The next line contains mm integers, the ii-th one is sziszi (1≤szi≤2001≤szi≤200). Notice that for i>1i>1, szi≥szi−1szi≥szi−1.
输出描述:
One integer, the maximum sum of the weights of taken cheeses.
示例1
输入
复制
5 3
2 10
2 5
1 22
3 7
6 8
1 3 7
备注:
In the example, Nazrin can take actions below to maximize the weight of taken cheeses:
In the first time, Nazrin stays at point 11 and gives up the first chance to take cheese.
In the second time, Nazrin takes the cheese between point 11 and point 22 and returns to point 11.
In the third time, Nazrin takes all cheeses between point 22 and point 55, and goes back to point 11.
思路:
首先考虑到sizei+1>sizei,所以当m>n时,只用保留最后n次即可。(前面的操作都取不到奶酪,可以去除 ) ,其次再预处理 l----r区间内空间为k的最大价值。随后再通过01背包进行选取就可以了
Ps:赛时是一点都没有想到,可恶啊
#include
#include
#include
#include
#include
#include
#include
#include
#include