目录
Problem 2. Connecting Two Barns
Problem 3. Convoluted Intervals
Problem 1. Closest cow wins
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 KK grassy patches (1≤K≤2⋅1051≤K≤2⋅105); the ii-th patch is located at position pipi and has an associated tastiness value titi (0≤ti≤1090≤ti≤109). Farmer John's nemesis, Farmer Nhoj, has already situated his MM cows (1≤M≤2⋅1051≤M≤2⋅105) at locations f1…fMf1…fM. All K+MK+M of these locations are distinct integers in the range [0,109][0,109].
Farmer John needs to pick NN (1≤N≤2⋅1051≤N≤2⋅105) 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.
拥有最靠近某个草地的奶牛的农夫拥有这一草地。如果来自两方农夫的两头奶牛距这一草地相等,则 Farmer Nhoj 拥有该草地。给定 Farmer Nhoj 的奶牛的位置以及草地的位置和美味值,求 Farmer John 的奶牛以最优方式放置时可以达到的最大总美味值。
INPUT FORMAT (input arrives from the terminal / stdin):
The first line contains K, M, and N.
第一行输入K,M,和N
The next KK lines each contain two space-separated integers pipi and titi.
后面K行输入pi和ti
The next MM lines each contain a single integer fifi.
后面M行输入fi
OUTPUT FORMAT (print output to the terminal / stdout):
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++).
SAMPLE INPUT:
6 5 2 0 4 4 6 8 10 10 8 12 12 13 14 2 3 5 7 11
SAMPLE OUTPUT:
36
If Farmer John places cows at positions 11.511.5 and 88 then he can claim a total tastiness of 10+12+14=3610+12+14=36.

本文包含三个算法问题:Closestcowwins关注如何最优放置奶牛以最大化美味值;ConnectingTwoBarns探讨如何通过最少成本建立路径连接两个牛棚;ConvolutedIntervals则要求计算特定条件下区间对的数量。
最低0.47元/天 解锁文章
478

被折叠的 条评论
为什么被折叠?



