hihoCoder 1595 : Numbers
Description
You are given n constant integers c[1], c[2], ..., c[n] and an integer k. You are to assign values to 2k integer variables, x[1], x[2], ..., x[k], y[1], y[2], ..., y[k], such that,
(1) For each 1 ≤ i ≤ k, x[i] ≤ y[i] holds,
(2) For each 1 ≤ i ≤ n, exists at least one such j (1 ≤ j ≤ k) that x[j] ≤ c[i] ≤ y[j].
Please find the minimum value of S=(y[1]+y[2]+...+y[k])-(x[1]+x[2]+...+x[k]).
Input
First line contains two integers n, k. (1 ≤ n, k ≤ 100000)
Following n lines contain integers c[1], c[2], ..., c[n]. (-1000000000 ≤ c[i] ≤ 1000000000)
Output
Output the minimum value of integer S.
Sample Hint
x[1]=-5, y[1]=4,
x[2]=10, y[2]=10.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,k,c[],d[];
long long ans;
bool cmp(int a,int b)
{
return a>b;
}
int main()
{int i;
cin>>n>>k;
for (i=;i<=n;i++)
{
scanf("%d",&c[i]);
}
sort(c+,c+n+);
ans=c[n]-c[];
for (i=;i<n;i++)
d[i]=c[i+]-c[i];
sort(d+,d+n,cmp);
for (i=;i<=k-;i++)
{
ans-=d[i];
}
cout<<ans;
}
hihoCoder 1595 : Numbers的更多相关文章
- hihoCoder挑战赛31
#1595 : Numbers 时间限制:8000ms 单点时限:1000ms 内存限制:256MB 描述 给定n个整数常数c[1], c[2], ..., c[n]和一个整数k.现在需要给2k个整数 ...
- hihoCoder #1349 Nature Numbers
题目大意 考虑自然数构成的序列 $a$:$01234567891011\dots$,序列下标从 $0$ 开始,即 $a_0 =0, a_1 = 1$ . 求 $a_n$($0\le n\le 10^{ ...
- hihoCoder 1432 : JiLi Number(吉利数)
hihoCoder #1432 : JiLi Number(吉利数) 时间限制:1000ms 单点时限:1000ms 内存限制:256MB Description - 题目描述 Driver Ji l ...
- [HihoCoder] Highway 高速公路问题
Description In the city, there is a one-way straight highway starts from the northern end, traverses ...
- hihocoder 1873 ACM-ICPC北京赛区2018重现赛 D Frog and Portal
http://hihocoder.com/problemset/problem/1873 时间限制:1000ms 单点时限:1000ms 内存限制:512MB 描述 A small frog want ...
- Java 位运算2-LeetCode 201 Bitwise AND of Numbers Range
在Java位运算总结-leetcode题目博文中总结了Java提供的按位运算操作符,今天又碰到LeetCode中一道按位操作的题目 Given a range [m, n] where 0 <= ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- [LeetCode] Add Two Numbers II 两个数字相加之二
You are given two linked lists representing two non-negative numbers. The most significant digit com ...
- [LeetCode] Maximum XOR of Two Numbers in an Array 数组中异或值最大的两个数字
Given a non-empty array of numbers, a0, a1, a2, … , an-1, where 0 ≤ ai < 231. Find the maximum re ...
随机推荐
- servlet3.0注解loadOnStartup不起作用解决方案
多次尝试3.0在源码中直接用注解配置loadOnStartup=1,即web应用启动时创建servlet实例,发现不起作用,但是在web.xml配置则可以正常运行.先上源码. package lee; ...
- Beta 第七天
今天遇到的困难: 构造新适配器的时候出现了某些崩溃的问题 ListView监听器有部分的Bug 今天完成的任务: 陈甘霖:完成相机调用和图库功能,完成阿尔法项目遗留下来的位置调用问题,实现百度定位 蔡 ...
- localhost访问不了的解决方法
c:\windows\system32\drivers\etc\hosts 用记事本打开,加入一行 127.0.0.1 localhost
- day-3 python多线程编程知识点汇总
python语言以容易入门,适合应用开发,编程简洁,第三方库多等等诸多优点,并吸引广大编程爱好者.但是也存在一个被熟知的性能瓶颈:python解释器引入GIL锁以后,多CPU场景下,也不再是并行方式运 ...
- Windows Powershell脚本执行
在cmd下执行powershell进入shell模式: 变量定义:$i = 10 $a = ifconfig | findstr "192" Windows下的命令都可以执行如: ...
- 在windows环境下安装redis和phpredis的扩展
在windows环境下安装redis和phpredis的扩展 1.首先配置php: 需要在windows的集成环境中找到php的扩展文件夹,ext,然后在网上寻找自己的php对应的.dll文件 比如说 ...
- JS实现页面内跳转
使用js($.ajax中)实现页面内跳转(即:描点平滑跳转)的方法(aa为跳转目的标签的id): 在网络上有很多资料所说的:animate方法我试了并不好使,不知道是啥原因,欢迎大家指正,附上网络方法 ...
- 图数据库orientDB(1-1)SQL基本操作
SQL基本操作 1.新增VerTex CREATE VERTEX V SET name="user01",sex="M",age="25"; ...
- KNN算法简单应用
这里是写给小白看的,大牛路过勿喷. 1 KNN算法简介 KNN(K-Nearest Neighbor)工作原理:存在一个样本数据集合,也称为训练样本集,并且样本集中每个数据都存在标签,即我们知道样本集 ...
- GridControl的常用操作
1.GridView的回车跳转单元格和换行 private void gridView1_KeyPress(object sender, KeyPressEventArgs e) { ...