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 ...
随机推荐
- php 获取地址栏参数
javascript实现: top.location.href 顶级窗口的地址this.location.href 当前窗口的地址 PHP实现: //获取域名或主机地址 echo $_SERVER[' ...
- sql数据库删除表的外键约束(INSERT 语句与 FOREIGN KEY 约束"XXX"冲突。该冲突发生于数据库"XXX",表"XXX", column 'XXX)
使用如下SQL语句查询出表中外键约束名称: 1 select name 2 from sys.foreign_key_columns f join sys.objects o on f.constra ...
- MySql-时间格式转换之转换为时分秒格式的日期
select date_format(create_datetime,'%Y-%m-%d %k:%i:%s') from busi_repairitem_category MySQL毫秒值和日期的指定 ...
- 使用内链接(A a inner join B b on a.xx = b.xx)查询2个表中某一列的相同的字段。
这里一句代码就是查询2个表中某一列的相同,可是查询出来之后B表因为有很多重复的id数据,然而查询出来的数据需要插入到临时表中,临时表的oid是不允许有重复的, 因此需要用到 distinct 函数来取 ...
- java解析XML获取城市代码
运行前先导入dom4j架包,由于我们公司用的代理服务器所以下面我设置了代理ip,不需要的可直接忽略 package com.chengshidaima.tools; import java.io.Bu ...
- opencv----人脸美白算法,祛斑,祛痘,磨皮等
现在各种手机camera软件都自带图像美颜处理,但是成熟的算法在网上很难搜到,博主也是自己摸索了自己做出来了,跟美图秀秀的处理效果相比,还不错,感觉很好,所以PO上来,与各位博友分享之. 首先是根据网 ...
- CodeForces 566B Replicating Processes
#include <bits/stdc++.h> #define N 3010 #define LL long long #define unsigned U using namespac ...
- checking for known struct flock definition... configure: error: Don't know how to define struct flock on this system, set --enable-opcache=
在对php进行安装的过程中出现如下错误: 1.报错信息: 1 checking for known struct flock definition... configure: error: Don't ...
- jquery 控制文本输入的字数
<textarea maxlength="200" id="remarks" onkeyup="title_len();">&l ...
- android 代码动态创建视图
LinearLayout 如何动态设置 margin? LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayou ...