C. Liebig's Barrels
You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble nbarrels consisting of k staves each, you can use any k staves to construct a barrel. Each stave must belong to exactly one barrel.
Let volume vj of barrel j be equal to the length of the minimal stave in it.
You want to assemble exactly n barrels with the maximal total sum of volumes. But you have to make them equal enough, so a difference between volumes of any pair of the resulting barrels must not exceed l, i.e. |vx - vy| ≤ l for any 1 ≤ x ≤ n and 1 ≤ y ≤ n.
Print maximal total sum of volumes of equal enough barrels or 0 if it's impossible to satisfy the condition above.
The first line contains three space-separated integers n, k and l (1 ≤ n, k ≤ 105,1 ≤ n·k ≤ 105, 0 ≤ l ≤ 109).
The second line contains m = n·k space-separated integers a1, a2, ..., am (1 ≤ ai ≤ 109) — lengths of staves.
Print single integer — maximal total sum of the volumes of barrels or 0 if it's impossible to construct exactly n barrels satisfying the condition |vx - vy| ≤ l for any 1 ≤ x ≤ n and1 ≤ y ≤ n.
4 2 12 2 1 2 3 2 2 3
7
2 1 010 10
20
1 2 15 2
2
3 2 11 2 3 4 5 6
0
In the first example you can form the following barrels: [1, 2], [2, 2], [2, 3], [2, 3].
In the second example you can form the following barrels: [10], [10].
In the third example you can form the following barrels: [2, 5].
In the fourth example difference between volumes of barrels in any partition is at least 2 so it is impossible to make barrels equal enough.
诸事不顺,操
一个贪心,其实就是分为n堆数,每堆数的最小值相差不能大于limit ,
求出n堆数最小值的和
upper_bound 返回的是第一个大于的数,减去1就是小于等于的数了
1 #include <bits/stdc++.h> 2 using namespace std; 3 const int maxn = 1e5 + 10; 4 long long a[maxn]; 5 int n, k, limit; 6 int main() { 7 scanf("%d%d%d", &n, &k, &limit); 8 for (int i = 0 ; i < n * k ; i++) 9 scanf("%lld", &a[i]); 10 sort(a, a + n * k ); 11 int temp = upper_bound(a, a + n * k, a[0] + limit) - a; 12 long long ans = 0; 13 int sum = n * k; 14 if (temp >= n) { 15 int temp1=temp; 16 while(sum > temp && sum - temp >= k - 1) { 17 sum -= k - 1; 18 ans += a[--temp1]; 19 } 20 for (int i = 0 ; i * k < temp1 ; i++) 21 ans += a[i * k]; 22 } 23 printf("%lld\n", ans); 24 return 0; 25 }
转载于:https://www.cnblogs.com/qldabiaoge/p/9071432.html
C. Liebig's Barrels相关推荐
- CodeForces-985C Liebig's Barrels
CodeForces-985C Liebig's Barrels Description You have m = n·k wooden staves. The i-th stave has leng ...
- cf Educational Codeforces Round 44 C. Liebig's Barrels
原题: C. Liebig's Barrels time limit per test2 seconds memory limit per test256 megabytes inputstandar ...
- codeforces+contest985C. Liebig's Barrels+greedy
//类似指针的想法 //偏移 C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes ...
- Codeforces #985C Liebig's Barrels
[问题描述] You have m = n·k wooden staves. The i-th stave has length ai. You have to assemble n barrels ...
- Educational Codeforces Round 44 (Rated for Div. 2)
题目链接:https://codeforces.com/contest/985 'A.Chess Placing 题意:给了一维的一个棋盘,共有n(n必为偶数)个格子.棋盘上是黑白相间的.现在棋盘上有 ...
- Codeforces 985C (贪心)
传送门 题面: C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input ...
- coderforce Educational Codeforces Round 44 (Rated for Div. 2) C(赛后补题)
C. Liebig's Barrels time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- 【codeforces 768F】 Barrels and boxes
http://codeforces.com/problemset/problem/768/F (题目链接) 题意 A,B两种物品可以装到栈中,每个栈只能存放一种物品,容量没有限制.现在讲所有栈排成一列 ...
- python电影数据分析的代码_python-small-examples
Kaggle电影数据分析实战 本项目基于Kaggle电影影评数据集,通过这个系列,你将学到如何进行数据探索性分析(EDA),学会使用数据分析利器pandas,会用绘图包pyecharts,以及EDA时 ...
最新文章
- TensorFlow被曝存在严重bug,搭配Keras可能丢失权重,用户反映一个月仍未修复
- GNU Readline 库及编程简介【转】
- 12.04 深圳站 | Serverless Developer Meetup 开放报名
- 登录mysql报错2059_navicat连接mysql8.0+版本报错2059
- 深度学习简介(一)——卷积神经网络
- haproxy配置代理tomcat和nginx_你真的掌握LVS、Nginx及HAProxy工作原理吗?
- 简述linux中动态库和静态库的制作调用流程
- js和jsp所有页面跳转总结
- latex导数_Latex:导数【高中常用公式】
- Linux——VMware虚拟机安装CentOS步骤
- android sha1和签名证书的学习
- Python爬虫之selenium高级功能
- SharePoint 2013 托管导航及相关配置
- vs 自动生成core dump文件
- Phoenix报错(5) org.apache.hadoop.hive.ql.metadata.HiveException
- 计算机cmd复制粘贴指令,win7系统使用CMD命令复制和删除文件夹的方法
- ios开发swift_10位Swift和iOS开发大师
- 【rviz_plugin Goal3DTools 深蓝路径规划 PluginlibFactory】
- VOB视频格式转换器怎么把vob转换为mp3
- 无法使用内置管理员账户打开照片,请使用其他账户登录,然后再试一次