A10607 | Polycarp's problems
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Polycarp is an experienced participant in Codehorses programming contests. Now he wants to become a problemsetter.
He sent to the coordinator a set of $n$ problems. Each problem has it's quality, the quality of the $i$ -th problem is $a_{i}$ ( $a_{i}$ can be positive, negative or equal to zero). The problems are ordered by expected difficulty, but the difficulty is not related to the quality in any way. The easiest problem has index $1$ , the hardest problem has index $n$ .
The coordinator's mood is equal to $q$ now. After reading a problem, the mood changes by it's quality. It means that after the coordinator reads a problem with quality $b$ , the value $b$ is added to his mood. The coordinator always reads problems one by one from the easiest to the hardest, it's impossible to change the order of the problems.
If after reading some problem the coordinator's mood becomes negative, he immediately stops reading and rejects the problemset.
Polycarp wants to remove the minimum number of problems from his problemset to make the coordinator's mood non-negative at any moment of time. Polycarp is not sure about the current coordinator's mood, but he has $m$ guesses "the current coordinator's mood $q=b_{i}$ ".
For each of $m$ guesses, find the minimum number of problems Polycarp needs to remove so that the coordinator's mood will always be greater or equal to $0$ while he reads problems from the easiest of the remaining problems to the hardest.
He sent to the coordinator a set of $n$ problems. Each problem has it's quality, the quality of the $i$ -th problem is $a_{i}$ ( $a_{i}$ can be positive, negative or equal to zero). The problems are ordered by expected difficulty, but the difficulty is not related to the quality in any way. The easiest problem has index $1$ , the hardest problem has index $n$ .
The coordinator's mood is equal to $q$ now. After reading a problem, the mood changes by it's quality. It means that after the coordinator reads a problem with quality $b$ , the value $b$ is added to his mood. The coordinator always reads problems one by one from the easiest to the hardest, it's impossible to change the order of the problems.
If after reading some problem the coordinator's mood becomes negative, he immediately stops reading and rejects the problemset.
Polycarp wants to remove the minimum number of problems from his problemset to make the coordinator's mood non-negative at any moment of time. Polycarp is not sure about the current coordinator's mood, but he has $m$ guesses "the current coordinator's mood $q=b_{i}$ ".
For each of $m$ guesses, find the minimum number of problems Polycarp needs to remove so that the coordinator's mood will always be greater or equal to $0$ while he reads problems from the easiest of the remaining problems to the hardest.
输入格式
The first line of input contains two integers $n$ and $m$ ( $1<=n<=750$ , $1<=m<=200000$ ) — the number of problems in the problemset and the number of guesses about the current coordinator's mood.
The second line of input contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $-10^{9}<=a_{i}<=10^{9}$ ) — the qualities of the problems in order of increasing difficulty.
The third line of input contains $m$ integers $b_{1},b_{2},...,b_{m}$ ( $0<=b_{i}<=10^{15}$ ) — the guesses of the current coordinator's mood $q$ .
The second line of input contains $n$ integers $a_{1},a_{2},...,a_{n}$ ( $-10^{9}<=a_{i}<=10^{9}$ ) — the qualities of the problems in order of increasing difficulty.
The third line of input contains $m$ integers $b_{1},b_{2},...,b_{m}$ ( $0<=b_{i}<=10^{15}$ ) — the guesses of the current coordinator's mood $q$ .
输出格式
Print $m$ lines, in $i$ -th line print single integer — the answer to the problem with $q=b_{i}$ .
输入输出样例
输入 #1
6 3 8 -5 -4 1 -7 4 0 7 3
输出 #1
2 0 1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted