题目链接: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. [转载]Oracle数据库 sql%found,sql%notfound,sql%rowcount

    sql%found,sql%notfound,sql%rowcount 在执行DML(insert,update,delete)语句时,可以用到以下三个隐式游标(游标是维护查询结果的内存中的一个区域, ...

  2. 三张图搞懂JavaScript的原型对象与原型链 / js继承,各种继承的优缺点(原型链继承,组合继承,寄生组合继承)

    摘自:https://www.cnblogs.com/shuiyi/p/5305435.html 对于新人来说,JavaScript的原型是一个很让人头疼的事情,一来prototype容易与__pro ...

  3. 瀑布流之ajax

    wf_js.html(展示页) <!DOCTYPE html> <html> <head> <meta charset="utf-8" / ...

  4. ubuntu 18.04下安装配置Hue问题记录

    前段时间将Hadoop 在ubuntu环境下装好,接下来尝试安装Hue来管理Hadoop,参照的资料有: 1.高可用Hadoop平台-Hue In Hadoop 2.ubuntu16.04 安装单机H ...

  5. java类中使用quartz,设置自动任务Demo

    package com.tech.jin.jobScheduler; import java.text.ParseException; import java.util.ArrayList; impo ...

  6. Could not complete request

    Could not complete request com.alibaba.dubbo.rpc.RpcException: Forbid consumer 10.254.1.26 access se ...

  7. be动词

    编辑 讨论 be动词,意思和用法很多,一般的意思是:是,此种用法,有多种变化形式,is,am,are,was,were,being,been,to be.另外,be动词还有成为的意思.根据句子中不同的 ...

  8. 【题解】 Luogu CF375D Tree and Queries

    原题传送门 这道题要用树链剖分,我博客里有对树链剖分的详细介绍 我博客中对莫队的详细介绍 莫队好题 我一上来想写线段树,随后觉得不好写并弃坑 我们可以看见没有修改操作,钦定莫队 但这是在树上,所以不能 ...

  9. 转:网卡、光纤网卡、ISCSI卡有什么区别?

    网卡.光纤网卡.ISCSI卡有什么区别? 感谢: http://www.it.com.cn/f/server/063/6/241650.htm 在讨论这个问题的时候,需要先说清楚一个问题:我们知道,在 ...

  10. 一、虚拟环境.二、路由配置主页与404.三、2.x路由分发.四、伪静态.五、request对象.六、FBV与CBV.七、文件上传.

    一.虚拟环境 ''' 解决版本共存 1. 用pycharm选择File点击NewProject然后选择virtualenv创建一个纯净环境 2. 打开下载的目录将venv文件夹下的所有文件(纯净的环境 ...