B. Tape
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You have a long stick, consisting of mm segments enumerated from 11 to mm . Each segment is 11 centimeter long. Sadly, some segments are broken and need to be repaired.

You have an infinitely long repair tape. You want to cut some pieces from the tape and use them to cover all of the broken segments. To be precise, a piece of tape of integer length tt placed at some position ss will cover segments s,s+1,…,s+t−1s,s+1,…,s+t−1 .

You are allowed to cover non-broken segments; it is also possible that some pieces of tape will overlap.

Time is money, so you want to cut at most kk continuous pieces of tape to cover all the broken segments. What is the minimum total length of these pieces?

Input

The first line contains three integers nn , mm and kk (1≤n≤1051≤n≤105 , n≤m≤109n≤m≤109 , 1≤k≤n1≤k≤n ) — the number of broken segments, the length of the stick and the maximum number of pieces you can use.

The second line contains nn integers b1,b2,…,bnb1,b2,…,bn (1≤bi≤m1≤bi≤m ) — the positions of the broken segments. These integers are given in increasing order, that is, b1<b2<…<bnb1<b2<…<bn .

Output

Print the minimum total length of the pieces.

Examples
Input

Copy
4 100 2
20 30 75 80
Output

Copy
17
Input

Copy
5 100 3
1 2 4 60 87
Output

Copy
6
Note

In the first example, you can use a piece of length 1111 to cover the broken segments 2020 and 3030 , and another piece of length 66 to cover 7575 and 8080 , for a total length of 1717 .

In the second example, you can use a piece of length 44 to cover broken segments 11 , 22 and 44 , and two pieces of length 11 to cover broken segments 6060 and 8787 .

就是有n个洞,消费为n,要消减成k,所有把n-k个两个洞合并,合并之后就会变成k堆

 
 
就是你先贴上,花费为n,你要把花费减到k,就是要合并n-k个两个洞的距离,差分出来取最小的n-k个再加上单独补
两个洞的pos差分是等于补一个洞和中间段的

,这时候就补上这k个洞即可。

#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <string.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+100;
int a[maxn],b[maxn];
int main()
{
int n,m,k;
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
for(int i=1;i<=n-1;i++) b[i]=a[i+1]-a[i];
sort(b+1,b+n);
ll sum=0;
for(int i=1;i<=n-k;i++) sum+=b[i];
sum+=k;
printf("%I64d\n",sum);
return 0;
}

  

tape ——cf的更多相关文章

  1. TensorFlow2 Part1:基础

    TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经网络 ...

  2. ORA-00494: enqueue [CF] held for too long (more than 900 seconds) by 'inst 1, osid 5166'

    凌晨收到同事电话,反馈应用程序访问Oracle数据库时报错,当时现场现象确认: 1. 应用程序访问不了数据库,使用SQL Developer测试发现访问不了数据库.报ORA-12570 TNS:pac ...

  3. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  4. cf Round 613

    A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...

  5. ARC下OC对象和CF对象之间的桥接(bridge)

    在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...

  6. [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现

    1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...

  7. CF memsql Start[c]UP 2.0 A

    CF memsql Start[c]UP 2.0 A A. Golden System time limit per test 1 second memory limit per test 256 m ...

  8. CF memsql Start[c]UP 2.0 B

    CF memsql Start[c]UP 2.0 B B. Distributed Join time limit per test 1 second memory limit per test 25 ...

  9. CF #376 (Div. 2) C. dfs

    1.CF #376 (Div. 2)    C. Socks       dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...

随机推荐

  1. [android] 在不同的activity之间传递数据

    新建一个activity,继承Activity 清单文件中进行配置,添加<activity/>节点 设置名称 android:name=”.类名” 点 代表的是当前包名,也可以不写 新建一 ...

  2. (8)Microsoft office Word 2013版本操作入门_制作传单海报

    1.纸张大小,方向设定. 1.1纸张大小: [页面布局]----[纸张大小] 可以选择已有的尺寸,也可以选择其他自定义的大小. 1.2 方向设定: [页面布局]--[纸张方向]选择 横向或者纵向 2. ...

  3. Java高并发--消息队列

    Java高并发--消息队列 主要是学习慕课网实战视频<Java并发编程入门与高并发面试>的笔记 举个例子:在购物商城下单后,希望购买者能收到短信或者邮件通知.有一种做法时在下单逻辑执行后调 ...

  4. python基础学习(七)列表

    列表的定义 List(列表) 是 Python 中使用 最频繁 的数据类型,在其他语言中通常叫做 数组(例如java.c) 专门用于存储 一串 信息 列表用 [] 定义,数据 之间使用 , 分隔 列表 ...

  5. 异常: Call From * 9000 failed on connection exception: java.net.ConnectException: Connection refused: no further information; For more details see: http://wiki.apache.org/hadoop/ConnectionRefused

    场景: eclipse链接不上阿里云hadoop解决: 将hadoop的配置文件中的ip改为内网IP即可

  6. ACM ICPC 2017 Warmup Contest 9 L

    L. Sticky Situation While on summer camp, you are playing a game of hide-and-seek in the forest. You ...

  7. 小tips:JS中this操作执行像(object.getName = object.getName)()操作改变了this

    var name = "The window"; var object = { name: "My Object", getName: function(){ ...

  8. 华为P20无线投屏到电脑 绝地求生投射电脑

    如今出门在外,必不可少的就是手机,如果没有了手机,每个人都会感觉没有安全感,感觉和世界失去了联系,我们每天每个人都在使用手机,但是作为华为手机用户的你,了解华为P20无线投屏到电脑是怎么操作的吗? 使 ...

  9. docker研究-2

    容器和虚拟机都是一种虚拟化技术,两者的主要区别: 虚拟机占用资源多,启动慢,荣誉步骤多:而容器启动快,占用资源少,体积小.Docker 属于 Linux 容器的一种封装,提供简单易用的容器使用接口.它 ...

  10. Java:字节流和字符流(输入流和输出流)

    本文内容: 什么是流 字节流 字符流 首发日期:2018-07-24 什么是流 流是个抽象的概念,是对输入输出设备的抽象,输入流可以看作一个输入通道,输出流可以看作一个输出通道. 输入流是相对程序而言 ...