题目链接:http://codeforces.com/contest/767/problem/D


D比C水系列。

将商店里面的牛奶按照保质期升序排序(显然优先买保质期久的)考虑二分答案,然后再将整个序列归并排序,贪心的检测答案是否正确即可。


 #include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 2001000
#define llg int
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
llg n,m,a[maxn],b[maxn],c[maxn],ans,tail,k; inline llg getint()
{
llg res=,fh=;char ch=getchar();
while((ch<''||ch>'')&&ch!='-')ch=getchar();
if(ch=='-')fh=-,ch=getchar();
while(ch<=''&&ch>='')res=res*+ch-'',ch=getchar();
return res*fh;
} struct node
{
llg val,wz;
}e[maxn]; bool cmp(llg a,llg b){return a>b;} bool cmpp(const node&a,const node&b){return a.val>b.val;} inline bool check(llg r2)
{
llg r1=n;
llg w1=,w2=; tail=;
while (w1<=r1 || w2<=r2)
{
if (w1>r1) c[++tail]=b[w2],w2++;
else if (w2>r2) c[++tail]=a[w1],w1++;
else if (a[w1]>b[w2])
{
c[++tail]=a[w1],w1++;
}
else
{
c[++tail]=b[w2],w2++;
}
}
llg x=tail+,t=;
while ()
{
for (llg i=;i<=k;i++)
{
x--;
if (x<=) return ;
if (c[x]<t) return ;
}
t++;
}
return ;
} int main()
{
yyj("D");
cin>>n>>m>>k;
for (llg i=;i<=n;i++) scanf("%d",&a[i]);
sort(a+,a+n+,cmp);
for (llg i=;i<=m;i++)
{
scanf("%d",&b[i]);
e[i].val=b[i],e[i].wz=i;
}
sort(b+,b+m+,cmp);
sort(e+,e+m+,cmpp);
llg l=,r=m,mid;
ans=-;
while (l<=r)
{
mid=(l+r)>>;
if (check(mid)) {ans=mid,l=mid+;}else r=mid-;
}
cout<<ans<<endl;
for (llg i=;i<=ans;i++) printf("%d ",e[i].wz);
return ;
}

Codeforces 767D - Cartons of milk的更多相关文章

  1. 【codeforces 767D】Cartons of milk

    [题目链接]:http://codeforces.com/problemset/problem/767/D [题意] 每个牛奶都有最晚可以喝的时间; 每天喝K瓶牛奶; 你有n瓶牛奶->已知每个牛 ...

  2. Codeforces Round #398 (Div. 2)

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

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

    这场cf时间特别好,周六下午,于是就打了打(谁叫我永远1800上不去div1) 比以前div2的题目更均衡了,没有太简单和太难的...好像B题难度高了很多,然后卡了很多人. 然后我最后做了四题,E题感 ...

  4. Codeforces Round #398 (Div. 2) A,B,C,D

    A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  5. Codeforces Round #398 (Div. 2) A B C D 模拟 细节 dfs 贪心

    A. Snacktower time limit per test 2 seconds memory limit per test 256 megabytes input standard input ...

  6. Codeforces Round #398 (Div. 2) A-E

    分数史上新低 开场5分钟过了A题,想着这次赌一把手速,先去切C吧 看完C题觉得这应该是道水题,码了十分钟提交,WA 想着这明明是道水题,估计少考虑了情况,添了几行再交,WA 不可能啊,这题都A不掉,和 ...

  7. Codeforces Round #342 (Div. 2) A - Guest From the Past 数学

    A. Guest From the Past 题目连接: http://www.codeforces.com/contest/625/problem/A Description Kolya Geras ...

  8. CodeForces - 93B(贪心+vector<pair<int,double> >+double 的精度操作

    题目链接:http://codeforces.com/problemset/problem/93/B B. End of Exams time limit per test 1 second memo ...

  9. 【15.07%】【codeforces 625A】Guest From the Past

    time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...

随机推荐

  1. Python智能检测编码并转码

    #安装包工具 $pip3 install chardet #直接打开文件,中文显示乱码 >>> import chardet >>> f = open('test. ...

  2. 自写Jquery插件 Datagrid

    原创文章,转载请注明出处,谢谢!https://www.cnblogs.com/GaoAnLee/p/9086582.html 废话不多说,先上个整体效果: html <div id='data ...

  3. ajax实现图片上传

    1.创建formData表单,模拟表单传递数据(formData有兼容性问题) var formData = new FormData();2.获取到相应的元素 var jobName = $(&qu ...

  4. JS笔记—03(DOM编程)

    1. 动态体现:HTML代码加载到浏览器,代码运行后改变文档(DOM树)增删改查节点.例如:ajax(不是新技术,是几个技术的合体js+http后台操作)就是这样的原理 2.js对象(浏览器对象.脚本 ...

  5. shell脚本一键安装redis集群[最终版]

    直接上shell了. #!/bin/bash #---------------------------------------------------------------------------- ...

  6. SqlBulkCopy类(将一个表插入到数据库)

    利用SqlBulkCopy类一次插入多条数据,即将一个表直接插入数据库. 首先,新建一个表,要保证表中的列名与数据库表的字段保持一致. 如果数据库一张TableMenuRole表,ID自增,MenuI ...

  7. 自动发现实现url+响应时间监控

    url自动发现脚本: [root@jenkins scripts]# cat  urlDiscovery.py #!/usr/bin/env python #coding:utf-8 import o ...

  8. ODAC(V9.5.15) 学习笔记(三)TOraSession(3)

    3. 选项 TOraSession的Options有如下内容 名称 类型 说明 CharLength TCharLength 单个字符的长度,缺省0,表示从服务器获取对应的字符集中单个字符长度 Cha ...

  9. 2.Android硬件访问服务编写系统代码【转】

    本文转载自:https://blog.csdn.net/qq_33443989/article/details/76696772 版权声明:本文为博主(Tower)自学笔记,欢迎转载! :-)     ...

  10. expr的字符串操作 表达式: length, index, match, substr等

    参考: http://www.linuxidc.com/Linux/2012-04/58095.htm expr的格式, 主要有两个, 一是 用expr option, 选项: 二是, expr的几个 ...