CodeForces 609D Gadgets for dollars and pounds
二分天数+验证
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int n,m,k;
long long s;
long long a[maxn],b[maxn],c[maxn];
int t[maxn];
long long A[maxn],B[maxn];
int preA[maxn],preB[maxn];
struct Tmp
{
int id;
long long val;
int day;
} tmp[maxn]; bool cmp(const Tmp&a,const Tmp&b)
{
return a.val<b.val;
} int main()
{
scanf("%d%d%d%lld",&n,&m,&k,&s);
for(int i=; i<=n; i++) scanf("%lld",&a[i]);
for(int i=; i<=n; i++) scanf("%lld",&b[i]);
for(int i=; i<=m; i++) scanf("%d%lld",&t[i],&c[i]); A[]=a[];
preA[]=;
for(int i=; i<=n; i++)
{
A[i]=min(A[i-],a[i]);
if(A[i-]<=a[i]) preA[i]=preA[i-];
else preA[i]=i;
} B[]=b[];
preB[]=;
for(int i=; i<=n; i++)
{
B[i]=min(B[i-],b[i]);
if(B[i-]<=b[i]) preB[i]=preB[i-];
else preB[i]=i;
} int l=,r=n;
int mid;
int ansDay=-;
while(l<=r)
{
mid=(l+r)/;
for(int i=; i<=m; i++)
{
tmp[i].id=i;
if(t[i]==) tmp[i].val=A[mid]*c[i];
else tmp[i].val=B[mid]*c[i];
}
sort(tmp+,tmp++m,cmp);
long long sum=;
for(int i=; i<=k; i++) sum=sum+tmp[i].val;
if(sum<=s)
{
ansDay=mid;
r=mid-;
}
else l=mid+;
}
printf("%d\n",ansDay);
if(ansDay!=-)
{
for(int i=; i<=m; i++)
{
tmp[i].id=i;
if(t[i]==) tmp[i].val=A[mid]*c[i];
else tmp[i].val=B[mid]*c[i]; if(t[i]==) tmp[i].day=preA[ansDay];
else tmp[i].day=preB[ansDay];
}
sort(tmp+,tmp++m,cmp);
for(int i=; i<=k; i++)
printf("%d %d\n",tmp[i].id,tmp[i].day);
}
return ;
}
CodeForces 609D Gadgets for dollars and pounds的更多相关文章
- codeforces 609D D. Gadgets for dollars and pounds(二分+贪心)
题目链接: D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 mega ...
- Codeforces Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分,贪心
D. Gadgets for dollars and pounds 题目连接: http://www.codeforces.com/contest/609/problem/C Description ...
- CF# Educational Codeforces Round 3 D. Gadgets for dollars and pounds
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- Educational Codeforces Round 3 D. Gadgets for dollars and pounds 二分+前缀
D. Gadgets for dollars and pounds time limit per test 2 seconds memory limit per test 256 megabytes ...
- Gadgets for dollars and pounds CodeForces - 609D
Nura wants to buy k gadgets. She has only sburles for that. She can buy each gadget for dollars or f ...
- CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题
对于这题笔者无解,只有手抄一份正解过来了: 基本思想就是 : 二分答案,对于第x天,计算它最少的花费f(x),<=s就是可行的,这是一个单调的函数,所以可以二分. 对于f(x)的计算,我用了nl ...
- Codeforces 609D 被二分教做人
传送门:http://codeforces.com/problemset/problem/609/D (如需转载,请注明出处,谢谢O(∩_∩)O) 题意: Nura想买k个小玩意,她手上有 s 个bu ...
- Educational Codeforces Round 3
A. USB Flash Drives 水题,排序即可 ]; int main() { int n,m; scanf("%d%d",&n,&m); ;i<n; ...
- 【249】◀▶IEW-Unit14
Unit 14 Money and Finance 线图写作技巧 1.Model1对应图片分析 The graph contains information about the price in US ...
随机推荐
- MinGW 运行C++程序的方法
1:安装好 MinGW 及 GCC 编译器后 , 当然 MinGW 全安装最保险了,不会太费劲 2:配置环境变量(注:可能需要重启后生效) 计算机 --> 属性 --> 高级系统设置 -- ...
- 关于C++中虚函数表存放位置的思考
其实这是我前一段时间思考过的一个问题,是在看<深入探索C++对象模型>这本书的时候我产生的一个疑问,最近在网上又看到类似的帖子,贴出来看看: 我看到了很多有意思的答案,都回答的比较好,下面 ...
- shell 变量说明
变量说明 $$Shell本身的PID(ProcessID)$!Shell最后运行的后台Process的PID$?最后运行的命令的结束代码(返回值)$-使用Set命令设定的Flag一览$*所有参数列表. ...
- 文件描述符和exec() close_on_exec
#include <fcntl.h> #include <iostream> #include <unistd.h> using namespace std; in ...
- Stammering Aliens
Stammering Aliens Time Limit: 2000MS Memory Limit: 65536K Description Dr. Ellie Arroway has ...
- ngnix配置文件
使用nginx最大的好处就是负载均衡. #设定负载均衡的服务器列表 upstream service{ server 10.4.29.174:7477; } server { ...
- linux(视频学习)2
第二部分(javaee的开发环境的搭建): 1. 安装jdk的过程: 安装ios的镜像文件,挂载到/mnt目录下.挂载: mount /mnt/cdrom卸载: umount /mnt/cdrom ...
- postgresql 在linux上的源码安装
http://my.oschina.net/hippora/blog/375292 下载源码并解压 [root@fnddb ~]# wget https://ftp.postgresql.org/pu ...
- GB2312、Unicode编码等
抛出问题: 我在CPP文件中,打算输出一行阿拉伯字符:
- reflow和repaint区别?
作者:zccst 重绘和重排之前也知道,但也没有可以详细了解他们的机制,区别,以及对性能的影响. A repaint occurs when changes are made to an elemen ...