tape ——cf
1 second
256 megabytes
standard input
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?
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 .
Print the minimum total length of the pieces.
4 100 2
20 30 75 80
17
5 100 3
1 2 4 60 87
6
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堆
两个洞的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的更多相关文章
- TensorFlow2 Part1:基础
TensorFlow™是一个基于数据流编程(dataflow programming)的符号数学系统,被广泛应用于各类机器学习(machine learning)算法的编程实现,其前身是谷歌的神经网络 ...
- 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 ...
- cf之路,1,Codeforces Round #345 (Div. 2)
cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅..... ...
- cf Round 613
A.Peter and Snow Blower(计算几何) 给定一个点和一个多边形,求出这个多边形绕这个点旋转一圈后形成的面积.保证这个点不在多边形内. 画个图能明白 这个图形是一个圆环,那么就是这个 ...
- ARC下OC对象和CF对象之间的桥接(bridge)
在开发iOS应用程序时我们有时会用到Core Foundation对象简称CF,例如Core Graphics.Core Text,并且我们可能需要将CF对象和OC对象进行互相转化,我们知道,ARC环 ...
- [Recommendation System] 推荐系统之协同过滤(CF)算法详解和实现
1 集体智慧和协同过滤 1.1 什么是集体智慧(社会计算)? 集体智慧 (Collective Intelligence) 并不是 Web2.0 时代特有的,只是在 Web2.0 时代,大家在 Web ...
- 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 ...
- 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 ...
- CF #376 (Div. 2) C. dfs
1.CF #376 (Div. 2) C. Socks dfs 2.题意:给袜子上色,使n天左右脚袜子都同样颜色. 3.总结:一开始用链表存图,一直TLE test 6 (1)如果需 ...
随机推荐
- WPF window 子窗口反馈效果(抖动/阴影渐变)
当设置了owner的子窗口显示后,点击子窗口外部,需要一种反馈机制(反馈动画). 实现: 1.触发源 每次点击子窗口外部,即母窗口时,事件捕捉如下 HwndSource hwndSource = Pr ...
- javascript中call()、apply()的区别
call().apply()的区别: 相同点: 1.call()和apply()都可以用来间接调用函数,都可以显式调用所需的this.即,锚点滑动任何函数可以作为任何对象的方法来调用. 2.两个方法都 ...
- CSS-水平和垂直居中
div中水平和垂直居中 width:200px;height:200px; /*设置div的大小*/ border:1px solid green; /*边框*/ text-align: center ...
- windows生成当前目录树
tree /f > list.txt 需要以管理员运行cmd
- Ne10编译安装
介绍 NEON,即"ARM Advanced SIMD",是ARM从ARMv7开始提供的高级单指令多数据(SIMD)扩展.它是一种64/128位混合SIMD体系结构.NEON在网上 ...
- 自定义控件详解(六):Paint 画笔MaskFilter过滤
首先看一个API:setMaskFilter(MaskFilter maskfilter): 设置MaskFilter,可以用不同的MaskFilter实现滤镜的效果,如滤化,立体等. 以下有两个Ma ...
- 基于OpenSSL的HTTPS通信C++实现
HTTPS是以安全为目标的HTTP通道,简单讲是HTTP的安全版.即HTTP下加入SSL层,HTTPS的安全基础是SSL,因此加密的详细内容就需要SSL.Nebula是一个为开发者提供一个快速开发 ...
- Django 配置MySQL数据库
在settings.py中配置 DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', # 数据库引擎 'NAME': 'my ...
- 设计模式java----单例模式
一.懒汉式单例 在第一次调用的时候实例化自己,Singleton的唯一实例只能通过getInstance()方法访问.线程不安全 /** * Created by Admin on 2017/3/19 ...
- [20190211]简单测试端口是否打开.txt
[20190211]简单测试端口是否打开.txt --//昨天看一个链接,提到如果判断一个端口是否打开可以简单执行如下:--//参考链接:https://dba010.com/2019/02/04/c ...