A803 | Greedy Gift Takers--Platinum
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John's nemesis, Farmer Nhoj, has $N$ cows ($1 \leq N \leq 10^5$),
conveniently numbered $1 \dots N$. They have unexpectedly turned up at Farmer
John's farm, so the unfailingly polite Farmer John is attempting to give them
gifts.
To this end, Farmer John has brought out his infinite supply of gifts, and
Nhoj's cows have queued up in front of him, with cow $1$ at the head of the
queue and cow $N$ at the tail. Farmer John was expecting that at every
timestep, the cow at the head of the queue would take a gift from Farmer John
and go to the tail of the queue. However, he has just realized that Nhoj's
cows are not that polite! After receiving her gift, each cow may not go to the
tail of the queue, but rather may cut some number of cows at the tail, and
insert herself in front of them. Specifically, cow $i$ will always cut exactly
$c_i$ cows ($0 \leq c_i \leq N-1$).
Farmer John knows that some cows might receive multiple gifts; as he has an
infinite supply, this does not worry him. But he is worried that some cows
might become unhappy if they do not get any gifts.
Help Farmer John find the number of cows who never receive any gifts, no
matter how many gifts are handed out.
conveniently numbered $1 \dots N$. They have unexpectedly turned up at Farmer
John's farm, so the unfailingly polite Farmer John is attempting to give them
gifts.
To this end, Farmer John has brought out his infinite supply of gifts, and
Nhoj's cows have queued up in front of him, with cow $1$ at the head of the
queue and cow $N$ at the tail. Farmer John was expecting that at every
timestep, the cow at the head of the queue would take a gift from Farmer John
and go to the tail of the queue. However, he has just realized that Nhoj's
cows are not that polite! After receiving her gift, each cow may not go to the
tail of the queue, but rather may cut some number of cows at the tail, and
insert herself in front of them. Specifically, cow $i$ will always cut exactly
$c_i$ cows ($0 \leq c_i \leq N-1$).
Farmer John knows that some cows might receive multiple gifts; as he has an
infinite supply, this does not worry him. But he is worried that some cows
might become unhappy if they do not get any gifts.
Help Farmer John find the number of cows who never receive any gifts, no
matter how many gifts are handed out.
输入格式
The first line contains a single integer, $N$.
The second line contains $N$ space-separated integers $c_1, c_2, \dots, c_N$.
The second line contains $N$ space-separated integers $c_1, c_2, \dots, c_N$.
输出格式
Please output the number of cows who cannot receive any gifts.
输入输出样例
输入 #1
3 1 2 0
输出 #1
1
暂无题解
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted