2015 多校赛 第二场 1004 hdu(5303)
The ith tree is planted at position xi, clockwise from position 0. There are ai delicious apple(s) on the ith tree.
You only have a basket which can contain at most K apple(s). You are to start from your storehouse, pick all the apples and carry them back to your storehouse using your basket. What is your minimum distance travelled?
1≤n,k≤105,ai≥1,a1+a2+...+an≤105
1≤L≤109
0≤x[i]≤L
There are less than 20 huge testcases, and less than 500 small testcases.
Then t testcases follow. In each testcase:
First line contains three integers, L,n,K.
Next n lines, each line contains xi,ai.
26
- #include<iostream>
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- #define maxn 100050
- int d_l[maxn],d_r[maxn],l,n,k,t,x,a,L,R;
- long long tot_l[maxn],tot_r[maxn],ans,tmp;
- int main(){
- scanf("%d",&t);
- while(t--){
- L=R=;
- scanf("%d%d%d",&l,&n,&k);
- for(int i=;i<n;i++){
- scanf("%d%d",&x,&a);
- for(int j=;j<a;j++){
- if(x*<l) d_l[++L]=x;
- else d_r[++R]=l-x;
- }
- }
- sort(d_l+,d_l+L+);
- sort(d_r+,d_r+R+);
- for(int i=;i<=L;i++){
- if(i<=k) tot_l[i]=d_l[i];
- else tot_l[i]=tot_l[i-k]+d_l[i];
- }
- for(int i=;i<=R;i++){
- if(i<=k) tot_r[i]=d_r[i];
- else tot_r[i]=tot_r[i-k]+d_r[i];
- }
- ans=(tot_l[L]+tot_r[R])*;
- for(int i=;i<=k;i++){
- tmp=(tot_l[L-i]+tot_r[max(,R-(k-i))])*;
- ans=min(ans,l+tmp);
- }
- printf("%I64d\n",ans);
- }
- return ;
- }
2015 多校赛 第二场 1004 hdu(5303)的更多相关文章
- 2015 多校赛 第二场 1006 (hdu 5305)
Problem Description There are n people and m pairs of friends. For every pair of friends, they can c ...
- 2015 多校赛 第二场 1002 (hdu 5301)
Description Your current task is to make a ground plan for a residential building located in HZXJHS. ...
- 2015 多校赛 第一场 1007 (hdu 5294)
总算今天静下心来学算法.. Description Innocent Wu follows Dumb Zhang into a ancient tomb. Innocent Wu’s at the e ...
- 2015 多校赛 第一场 1002 (hdu 5289)
Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...
- 2015 多校赛 第一场 1001 (hdu 5288)
Description OO has got a array A of size n ,defined a function f(l,r) represent the number of i (l&l ...
- 多校第二场 1004 hdu 5303 Delicious Apples(背包+贪心)
题目链接: 点击打开链接 题目大意: 在一个周长为L的环上.给出n棵苹果树.苹果树的位置是xi,苹果树是ai,苹果商店在0位置,人的篮子最大容量为k,问最少做多远的距离可以把苹果都运到店里 题目分析: ...
- 2019HDU多校赛第二场 H HDU 6598 Harmonious Army(最小割模型)
参考博客https://blog.csdn.net/u013534123/article/details/97142191 #include<bits/stdc++.h> using na ...
- 可持久化线段树的学习(区间第k大和查询历史版本的数据)(杭电多校赛第二场1011)
以前我们学习了线段树可以知道,线段树的每一个节点都储存的是一段区间,所以线段树可以做简单的区间查询,更改等简单的操作. 而后面再做有些题目,就可能会碰到一种回退的操作.这里的回退是指回到未做各种操作之 ...
- SCNU省选校赛第二场B题题解
今晚的校赛又告一段落啦,终于"开斋"了! AC了两题,还算是满意的,英语还是硬伤. 来看题目吧! B. Array time limit per test 2 seconds me ...
随机推荐
- 用cmd查看win8版本 激活等详细信息命令
Win+x===>选择以管理员身份运行,输入: slmgr /dlv 显示:最为详尽的激活信息,包括:激活ID.安装ID.激活截止日期slmgr /dli 显示:操作系统版本.部分产品密钥. ...
- 【sqli-labs】 less11 POST - Error Based - Single quotes- String (基于错误的POST单引号字符型注入)
查看源码,用户名和密码通过post提交 加单引号提交 出现报错,推测对应的SQL语句 , 直接使用or构造永真登录 成功,注意此处登录的用户为表中的第一个用户 需要改变用户可以通过改变筛选条件实现 作 ...
- Java Web_过滤器
过滤器分类: Servlet2.5: request:用户直接访问页面时,Web容器将会调用过滤器. forward:目标资源是通过RequestDispatcher的forward访问时,该过滤器将 ...
- Qt5.11+opencv3.4的配置安装
系统:Windows 10 64位 前期准备: 1.CMake下载安装 下载地址:https://cmake.org/download/ 选择msi安装文件,按照提示一步一步按照就好 可以参考:htt ...
- java 定时器任务模板
1.该定时任务是基于web.xml的监听机制 listener 来实现的 建立监听类: NFDFlightDataTaskListener.java import javax.servlet.Serv ...
- 【*2000】【2018-2019 ICPC, NEERC, Southern Subregional Contest C 】Cloud Computing
[链接] 我是链接,点我呀:) [题意] [题解] 我们可以很容易知道区间的每个位置有哪些安排可以用. 显然 我们优先用那些花费的钱比较少的租用cpu方案. 但一个方案可供租用的cpu有限. 我们可以 ...
- hdu 1716 深搜dfs
#include<stdio.h> #include<stdlib.h> #include<string.h> #define N 5 int f[N]; int ...
- 转载 - Tarjan算法(求SCC)
出处:http://blog.csdn.net/xinghongduo/article/details/6195337 说到以Tarjan命名的算法,我们经常提到的有3个,其中就包括本文所介绍的求强连 ...
- 转载 - KMP算法
出处:http://www.cnblogs.com/dolphin0520/archive/2011/08/24/2151846.html KMP算法 在介绍KMP算法之前,先介绍一下BF算法. 一. ...
- 心急的C小加 贪心算法
心急的C小加 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 C小加有一些木棒,它们的长度和质量都已经知道,需要一个机器处理这些木棒,机器开启的时候需要耗费一个单位的 ...