题目链接: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. POJ 1018 Communication System (动态规划)

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  2. Linux系统管理和维护常用命令

    Linux系统管理和维护常用命令 ls 命令 功能说明 ls 命令显示指定工作目录下的内容,列出工作目录所包含的文件及子目录. 语法结构: ls [选项] [路径或文件] ls 选项及说明 -a 显示 ...

  3. Installing Android Studio

    To set up Android Studio on Windows: Launch the .exe file you just downloaded. Follow the setup wiza ...

  4. Maven工程打成一个jar包

    1:maven-shade-plugin 插件 <plugin> <groupId>org.apache.maven.plugins</groupId> <a ...

  5. 线性回归、Logistic回归、Softmax回归

    线性回归(Linear Regression) 什么是回归? 给定一些数据,{(x1,y1),(x2,y2)…(xn,yn) },x的值来预测y的值,通常地,y的值是连续的就是回归问题,y的值是离散的 ...

  6. linux 压缩工具

    gzip gunzip zcat bzip2 bunzip2 bzcat xz unxz xzcat a:  gzip 用法 # gzip file  压缩文件 不会保留源文件 直接生成 file.g ...

  7. Python3 tkinter基础 Label imag显示图片

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  8. Python3基础 list extend 合并列表

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  9. Python3基础 list count 查询指定元素在列表中出现了多少次

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. salt stack 远程命令

    salt stack 远程命令 salt stack是一种自动化的运维工具,可以同时对N台服务器进行配置管理.远程命令执行等操作. salt stack分为两个部分 salt-master,部署在控制 ...