二分天数+验证

#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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. CodeForce---Educational Codeforces Round 3 D. Gadgets for dollars and pounds 正题

    对于这题笔者无解,只有手抄一份正解过来了: 基本思想就是 : 二分答案,对于第x天,计算它最少的花费f(x),<=s就是可行的,这是一个单调的函数,所以可以二分. 对于f(x)的计算,我用了nl ...

  7. Codeforces 609D 被二分教做人

    传送门:http://codeforces.com/problemset/problem/609/D (如需转载,请注明出处,谢谢O(∩_∩)O) 题意: Nura想买k个小玩意,她手上有 s 个bu ...

  8. Educational Codeforces Round 3

    A. USB Flash Drives 水题,排序即可 ]; int main() { int n,m; scanf("%d%d",&n,&m); ;i<n; ...

  9. 【249】◀▶IEW-Unit14

    Unit 14 Money and Finance 线图写作技巧 1.Model1对应图片分析 The graph contains information about the price in US ...

随机推荐

  1. Shell 流程控制-if for case while until break continue

    Shell 流程控制 和Java.PHP等语言不一样,sh的流程控制不可为空,如(以下为PHP流程控制写法): <?php if (isset($_GET["q"])) { ...

  2. 安卓四大组件的作用、安卓Service的作用

    Activity好像是应用程式的眼睛,提供与user互动之窗. BroadcastReceiver好像是耳朵,接收来自各方的Intent. Service是在后台运行的. 一个Service 是一段长 ...

  3. linux文件系统命令

    1. df df -h 2.查看文件系统的类型 df -T tmpfs文件系统所知道的就是它正在使用某种形式的虚拟内存.tmpfs是一种基于内存的文件系统.而tmpfs是一个文件系统,并不是块设备,只 ...

  4. LightOJ 1259 Goldbach`s Conjecture 素数打表

    题目大意:求讲一个整数n分解为两个素数的方案数. 题目思路:素数打表,后遍历 1-n/2,寻找方案数,需要注意的是:C/C++中 bool类型占用一个字节,int类型占用4个字节,在素数打表中采用bo ...

  5. apicloud本地测试安卓测试包安装

    1.liutingdeMacBook-Pro:~ js-lt$ which adb 2.liutingdeMacBook-Pro:~ js-lt$ ls 3.liutingdeMacBook-Pro: ...

  6. 初识Jmeter(一)

    倒霉熊的推荐: 文本学习网址:http://m.open-open.com/m/doc/category/105 视频学习网址: 软件学习网:http://www.ask3.cn/index.html ...

  7. Bom2016/4/21

    Browser Object Model 浏览器对象模型 open(地址,打开方式) open('http://www.baidu.com','_self')本窗口打开百度 open('http:// ...

  8. ice grid 第一篇

    关键点: (1)如果想提高并发的话,还是在一个node上对于同一个application开多个server instance. 1.名词解释 .Replica groups A replica gro ...

  9. js插入节点appendChild和insertBefore

    首先 从定义来理解 这两个方法: appendChild() 方法:可向节点的子节点列表的末尾添加新的子节点.语法:appendChild(newchild) insertBefore() 方法:可在 ...

  10. AJAX开发技术--AJAX简介

    Asynchronous  JavaScript and XML,异步JavaScript和XML 主要目的用于页面的局部刷新.不用全部刷新,提高性能. 在AJAX中主要是通过XMLHttpReque ...