Codeforces Round #398(Div. 2)D. Cartons of milk

别再只盯着照片了!手把手教你用Python提取大疆照片里的GPS、姿态和RTK数据 本文详细介绍了如何使用Python提取大疆照片中的GPS、姿态和RTK数据,帮助用户解锁无人机拍摄照片中的隐藏元数据。通过实战代码示例,展示了如何解析EXIF格式的定位、姿态和RTK状态信息,并实现批量处理与数据分析,适用于测绘、农业巡检等专业领域。 阅读详情


D. Cartons of milk
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

Olya likes milk very much. She drinks k cartons of milk each day if she has at least k and drinks all of them if she doesn't. But there's an issue — expiration dates. Each carton has a date after which you can't drink it (you still can drink it exactly at the date written on the carton). Due to this, if Olya's fridge contains a carton past its expiry date, she throws it away.

Olya hates throwing out cartons, so when she drinks a carton, she chooses the one which expires the fastest. It's easy to understand that this strategy minimizes the amount of cartons thrown out and lets her avoid it if it's even possible.

Milk. Best before: 20.02.2017.

The main issue Olya has is the one of buying new cartons. Currently, there are n cartons of milk in Olya's fridge, for each one an expiration date is known (how soon does it expire, measured in days). In the shop that Olya visited there are m cartons, and the expiration date is known for each of those cartons as well.

Find the maximum number of cartons Olya can buy so that she wouldn't have to throw away any cartons. Assume that Olya drank no cartons today.

Input

In the first line there are three integers n, m, k (1 ≤ n, m ≤ 106, 1 ≤ k ≤ n + m) — the amount of cartons in Olya's fridge, the amount of cartons in the shop and the number of cartons Olya drinks each day.

In the second line there are n integers f1, f2, ..., fn (0 ≤ fi ≤ 107) — expiration dates of the cartons in Olya's fridge. The expiration date is expressed by the number of days the drinking of this carton can be delayed. For example, a 0 expiration date means it must be drunk today, 1 — no later than tomorrow, etc.

In the third line there are m integers s1, s2, ..., sm (0 ≤ si ≤ 107) — expiration dates of the cartons in the shop in a similar format.

Output

If there's no way for Olya to drink the cartons she already has in her fridge, print -1.

Otherwise, in the first line print the maximum number x of cartons which Olya can buy so that she wouldn't have to throw a carton away. The next line should contain exactly x integers — the numbers of the cartons that should be bought (cartons are numbered in an order in which they are written in the input, starting with 1). Numbers should not repeat, but can be in arbitrary order. If there are multiple correct answers, print any of them.

Examples
input
3 6 2
1 0 1
2 0 2 0 0 2
output
3
1 2 3
input
3 1 2
0 0 0
1
output
-1
input
2 1 2
0 1
0
output
1
1 
Note

In the first example k = 2 and Olya has three cartons with expiry dates 0, 1 and 1 (they expire today, tomorrow and tomorrow), and the shop has 3 cartons with expiry date 0 and 3 cartons with expiry date 2. Olya can buy three cartons, for example, one with the expiry date 0 and two with expiry date 2.

In the second example all three cartons Olya owns expire today and it means she would have to throw packets away regardless of whether she buys an extra one or not.

In the third example Olya would drink k = 2 cartons today (one she alreay has in her fridge and one from the shop) and the remaining one tomorrow.


题意:家里有n瓶牛奶,超市有m瓶牛奶,主人每天喝k瓶,牛奶有保质期,问在不浪费的情况下,最多能买几瓶牛奶,家里的n瓶牛奶若有浪费输出-1.

思路:很明显贪心的方案是这样的,家里的牛奶保质期越短越早喝越好,超市的牛奶保质期越长,买它越好,家里的牛奶能不能喝完排下序就出答案了,然后就是超市的牛奶买几瓶最好,这里我们二分答案判断就好了,判断的时候不能把两个数组合并然后排序,这样每次判断都要排序会超时的,这里用点技巧就不用排序了,下面给代码:

#include<cstdio>  
#include<algorithm>  
#include<cstring>  
#include<iostream>  
#include<cmath>  
#include<queue>  
#include<functional>  
typedef long long LL;
using namespace std;
#define maxn 1000005
#define ll l,mid,now<<1  
#define rr mid+1,r,now<<1|1  
#define lson l1,mid,l2,r2,now<<1  
#define rson mid+1,r1,l2,r2,now<<1|1  
#define inf 0x3f3f3f3f  
const int mod = 1e9 + 7;
int a[maxn];
int n, m, k;
struct node{
	int value, id;
}b[maxn];
bool check(int num){
	int now1 = 0, now2 = 0;
	while (now1 + now2<n + num){
		if (now1 < n){
			if (now2 < num){
				if (a[now1] < b[num-now2-1].value){
					if ((now1 + now2) / k > a[now1])
						return false;
					else
						now1++;
				}
				else{
					if ((now1 + now2) / k > b[num-now2-1].value)
						return false;
					else
						now2++;
				}
			}
			else{
				if ((now1 + now2) / k > a[now1])
					return false;
				else
					now1++;
			}
		}
		else{
			if ((now1 + now2) / k > b[num-now2-1].value)
				return false;
			else
				now2++;
		}
	}
	return true;
}
bool cmp(node x, node y){
	return x.value > y.value;
}
int main(){
	scanf("%d%d%d", &n, &m, &k);
	for (int i = 0; i < n; i++){
		scanf("%d", &a[i]);
	}
	for (int i = 0; i < m; i++){
		scanf("%d", &b[i].value);
		b[i].id = i + 1;
	}
	sort(a, a + n);
	bool jud = true;
	for (int i = 0; i < n; i++){
		if (i / k>a[i]){
			jud = false;
			break;
		}
	}
	if (jud){
		sort(b, b + m, cmp);
		int l = 1, r = m;
		int ans = 0;
		while (l <= r){
			int mid = l + r >> 1;
			if (check(mid)){
				l = mid + 1;
				ans = mid;
			}
			else{
				r = mid - 1;
			}
		}
		printf("%d\n", ans);
		if (ans)
			printf("%d", b[0].id);
		for (int i = 1; i < ans; i++){
			printf(" %d", b[i].id);
		}
		printf("\n");
	}
	else
		printf("-1\n");
}



eda、gnm、anm究竟是个啥? eda:主成分分析 gnm:高斯网络模型 anm:各向异性网络模型 阅读详情

相关推荐

STM32G474片内运放实战:从独立模式到PGA与ADC采样链路

在嵌入式控制系统中,运放是连接模拟信号与数字处理的关键环节。传统方案依赖外部分立运放搭建放大电路,存在成本高、PCB布局敏感、一致性差等痛点。STM32G474在MCU内部集成多路可编程运放(OPAMP),支持独立模式、跟随器、PGA以及比较器模式,配合内部ADC和DMA可构成完整模拟采集链路。通过片内互联,信号路径大幅缩短,抗干扰性和通道一致性显著提升,尤其适用于电机电流采样、数字电源等场景。本文以STM32G474为例,详解从独立模式到PGA增益配置,再到ADC与DMA联动调试的完整过程,并给出采样时间

weixin_29194255的博客 246

Codeforces Round #398(Div. 2)D. Cartons of milk【二分+暴力处理】

D. Cartons of milk time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Olya likes milk very much. She drinks k cartons of

mengxiang000000 1011

Codeforces Round #401 (Div. 2) D. Cloud of Hashtags

#include<bits/stdc++.h> using namespace std; #define X first #define Y second #define eps 1e-2 #define gcd __gcd #define pb push_back #define PI acos(-1.0) #define lowbit(x) (x)&(-x) #define bug printf("!!!!!\n"); #define mem(x,y) memset(x,y,s

我们仍未知道那天所看见的花的名字。 287

Opencv2.4.9源码分析——HoughCircles

图形可以用一些参数进行表示,标准霍夫变换的原理就是把图像空间转换成参数空间(即霍夫空间),例如霍夫变换的直线检测就是在距离-角度空间内进行检测。圆可以表示成: (x-a)2+(y-b)2=r2                   (1) 其中a和b表示圆心坐标,r表示圆半径,因此霍夫变换的圆检测就是在这三个参数组成的三维空间内进行检测。 原则上,霍夫变换可以检测任何形状。但复杂的形状需要的

赵春江的专栏 3万+

OpenWRT二级路由DHCP客户端配置:实现IPv4 WAN自动获取与网段隔离

本文详细讲解了如何将OpenWRT配置为二级路由器,重点在于设置其WAN口为DHCP客户端以自动获取IPv4地址,并修改LAN口网段实现与上级网络的隔离。文章提供了从网络拓扑规划、具体配置步骤到防火墙设置的完整指南,并分享了常见问题排查与避坑经验,帮助用户构建稳定且功能独立的家庭网络环境。

weixin_29268267的博客 293

CodeForces 767 D.Cartons of milk(贪心)

Description 一个人一天要喝kkk瓶牛奶,如果冰箱里的牛奶不够kkk瓶就全部喝完,目前冰箱里有nnn瓶牛奶,给出每瓶牛奶的保质期,即还有几天会过期,过期的牛奶要被扔掉,再给出商店中mmm瓶牛奶的保质期,问是否存在一种方案使得这个人不扔掉任何一瓶牛奶,如果有,他最多可以从商店买多少瓶牛奶 Input 第一行三个整数n,m,kn,m,kn,m,k表示已有牛奶数量,商店里牛奶数量和每天...

ZSQ 499

【生信】全基因组测序(WGS)

1、全基因组测序(WGS) 的定义 2、GWS流程 2.1准备工作——分析软件 2.2原始数据质控 2.3数据预处理 2.4变异检测

weixin_40695088的博客 4万+

Codeforces Round #398

A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output According to an old legeng, a long time ago Ankh-Morpor

cxy666 580

【多元统计分析】均值向量和协方差阵的检验——spss上机实验

均值向量和协方差阵的检验——spss上机实验 #参考书目为《多元统计分析》(第五版)——何晓群.中国人民大学出版社 #如有错误,请指正!谢谢~ #关注公众号搜索同名文章获取数据~ 习题2.3 现选取内蒙古、广西、贵州、云南、西藏、宁夏、新疆、甘肃和青海等9个内陆边远省区。选取人均GDP、第三产业比重、人均消费支出、人口自然增长率及文盲半文盲人口占15岁以上人口的比例等5项能较好的说明各地区社会经济发展水平的指标,验证边远及少数民族聚居区的社会经济发展水平与全国平均水平间有无显著差异。 将输入导入spss

suansuannainaizi的博客 3万+

jenkins安装、打包、部署

一个可以让小白部署发布项目的软件;git 配置 一定要配置git的命令路径jenkins启动命令,一定要加这一段 -Dhudson.util.ProcessTree.disable=true一定要配置jenkins的节点,BUILD_ID和DONTKILLME 否则会导致打包后,会将运行的java程序进程也杀死创建任务SSH中执行服务器B的命令的时候,cd /opt;一定要cd 打开那个目录,否则文件无法传输过去。

学海无涯,我用JAVA 5217

Codeforces Round #398 D题Cartons of milk(二分,贪心)解题报告

D. Cartons of milk time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Olya likes milk very much. She drinkskcartons ...

weixin_30925411的博客 191

Open3D KD-tree的使用【2025最新版】

Open3d使用FLANN构建KDTree以便进行快速最近邻检索。博客长期更新,本文最近一次更新时间为:2025年1月1日,代码已同步更新至Open3D 0.18.0版本。

点云侠的博客 40万+

【Codeforces Round #398 (Div. 2)】Codeforces 767D Cartons of milk

二分答案+贪心

YHaX的博客 997

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Codeforces Round #398 (Div. 2) D. Cartons of milk —— 二分

题目链接:http://codeforces.com/contest/767/problem/D 代码如下: #include #include #include #include #include #include #include #include #include #include #include #define LL long long #define MAX(a,b) (a

A man can be destroyed, but not defeated. 510

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

Codeforces Round #398 (Div. 2) D. Cartons of milk

D. Cartons of milk time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Olya likes milk very much. She drinks k 

jerans的博客 361

ET2012新版免狗免安装绿色软件

ET2012新版免狗免安祖昂绿色软件。,新界面,新视觉,

Codeforces Round #398 (Div. 2) D. Cartons of milk

二分+双指针

我们仍未知道那天所看见的花的名字。 136

Codeforces Round #398 (Div. 2) D. Cartons of milk(二分+贪心)

题目链接 思路:二分答案,如果x能满足的话,0 1 2.。。x-1也肯定都能满足,我们优先喝即将过期的牛奶,看看能不能喝完。 #include<bits/stdc++.h> using namespace std; typedef long long ll; const ll maxn=1e6+1; ll a[maxn],k; pair<ll,int>b[maxn];...

qq_42479630的博客 143

Codeforces Round #398 (Div. 2)

Codeforces Round #398 (Div. 2) A.Snacktower 模拟 我和官方题解的命名神相似...$has$ #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <cmath...

weixin_30929295的博客 74

Codeforces Round #398 (Div. 2) A.Snacktower B.The Queue C.Garland D.Cartons of milk E.Change-fr

A#include <bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define rep(i,a,b) for(int i=a;i<b;i++) #define debug(a) printf("a =: %d\n",a); #define sc(x) scanf("%d",&x) const int INF=0x3f3f3f3f; c

Martin的博客 1319

Codeforces Round #398 (div.2)简要题解

这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人。 然后我最后做了四题,E题感觉不会太难就是切不下来,还好前面几题A的快居然混了个RANK6,然后+204,终于上到紫名了...... ---------我是分割线君 A.Snacktower 有一个1到n的全排列,按顺...

weixin_30611509的博客 89

CodeForces 767D Cartons of milk

二分,排序。 首先感觉题意有问题,什么叫假设今天不喝...... 将$f$从小到大排序,$s$也从小到大排序,肯定是期日期大的先买,因此可以对$s$进行二分,然后验证。 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio> #include<cstring> #inc...

weixin_33982670的博客 179

hdu 6070 Dirt Ratio

Dirt Ratio Time Limit: 18000/9000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 384    Accepted Submission(s): 120 Special Judge Problem Description I

overload1997 827

2016 ICPC大连赛区 hdu5976 Detachment

Detachment Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 437    Accepted Submission(s): 144 Problem Description In a highly devel

overload1997 718

HDU 3681 Prison Break

Prison Break Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 4726    Accepted Submission(s): 1288 Problem Description Rompire is a

overload1997 637

Codeforces732D Exams

D. Exams time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasiliy has an exam period which will continue for 

overload1997 530
上一篇: Codeforces Round #398 (Div. 2) C. Garland
下一篇: Codeforces 768B Code For 1
overload1997
博客等级 码龄11年 328粉丝 210原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值