A845 | Closest Cow Wins--Silver
来源USACO
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
Farmer John owns a long farm along the highway that can be considered somewhat
like a one-dimensional number line. Along the farm, there are $K$ grassy
patches ($1 \leq K \leq 2\cdot 10^5$); the $i$-th patch is located at position
$p_i$ and has an associated tastiness value $t_i$ ($0\le t_i\le 10^9$). Farmer
John's nemesis, Farmer Nhoj, has already situated his $M$ cows ($1 \leq M \leq
2\cdot 10^5$) at locations $f_1 \ldots f_M$. All $K+M$ of these locations are
distinct integers in the range $[0,10^9]$.
Farmer John needs to pick $N$ ($1\le N\le 2\cdot 10^5$) locations (not
necessarily integers) for his cows to be located. These must be distinct from
those already occupied by the cows of Farmer Nhoj, but it is possible for
Farmer John to place his cows at the same locations as grassy patches.
Whichever farmer owns a cow closest to a grassy patch can claim ownership of
that patch. If there are two cows from rival farmers equally close to the
patch, then Farmer Nhoj claims the patch.
Given the locations of Farmer Nhoj's cows and the locations and tastiness
values of the grassy patches, determine the maximum total tastiness Farmer
John's cows can claim if optimally positioned.
like a one-dimensional number line. Along the farm, there are $K$ grassy
patches ($1 \leq K \leq 2\cdot 10^5$); the $i$-th patch is located at position
$p_i$ and has an associated tastiness value $t_i$ ($0\le t_i\le 10^9$). Farmer
John's nemesis, Farmer Nhoj, has already situated his $M$ cows ($1 \leq M \leq
2\cdot 10^5$) at locations $f_1 \ldots f_M$. All $K+M$ of these locations are
distinct integers in the range $[0,10^9]$.
Farmer John needs to pick $N$ ($1\le N\le 2\cdot 10^5$) locations (not
necessarily integers) for his cows to be located. These must be distinct from
those already occupied by the cows of Farmer Nhoj, but it is possible for
Farmer John to place his cows at the same locations as grassy patches.
Whichever farmer owns a cow closest to a grassy patch can claim ownership of
that patch. If there are two cows from rival farmers equally close to the
patch, then Farmer Nhoj claims the patch.
Given the locations of Farmer Nhoj's cows and the locations and tastiness
values of the grassy patches, determine the maximum total tastiness Farmer
John's cows can claim if optimally positioned.
输入格式
The first line contains $K$, $M$, and $N$.
The next $K$ lines each contain two space-separated integers $p_i$ and $t_i$.
The next $M$ lines each contain a single integer $f_i$.
The next $K$ lines each contain two space-separated integers $p_i$ and $t_i$.
The next $M$ lines each contain a single integer $f_i$.
输出格式
An integer denoting the maximum total tastiness. Note that the answer to this
problem can be too large to fit into a 32-bit integer, so you probably want to
use 64-bit integers (e.g., "long long"s in C or C++).
problem can be too large to fit into a 32-bit integer, so you probably want to
use 64-bit integers (e.g., "long long"s in C or C++).
输入输出样例
输入 #1
6 5 2 0 4 4 6 8 10 10 8 12 12 13 14 2 3 5 7 11
输出 #1
36
If Farmer John places cows at positions $11.5$ and $8$ then he can claim a
total tastiness of $10+12+14=36$.
total tastiness of $10+12+14=36$.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted