二分天数+验证

#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. 去掉input text后面的叉

    如题 input[type=text]::-ms-clear{ display: none; } input::-webkit-search-cancel-button{ display: none; ...

  2. Winsock SPI-Socks5-SSL

  3. linux centos下安装g++

    1.查看是否安装 g++ -v 2.命令直接安装 yum install gcc-c++ 3.提示你找不到g++安装包,执行下面命令 yum install gcc-c++ libstdc++-dev ...

  4. sql优化__rownum的使用【转】

    ROWNUM的概念ROWNUM是一个虚假的列.它将被分配为 1,2,3,4,...N,N 是行的数量.一个ROWNUM值不是被永久的分配给一行 (这是最容易被误解的).表中的某一行并没有标号:你不可以 ...

  5. linux的学习系列 8---进程管理

    当我们运行程序时,Linux会为程序创建一个特殊的环境,该环境包含程序运行需要的所有资源,以保证程序能够独立运行,不受其他程序的干扰.这个特殊的环境就称为进程. 每个 Linux 命令都与系统中的程序 ...

  6. iOS 6 Passbook 入门 1/2

    http://www.raywenderlich.com/zh-hans/23066/ios-6-passbook-%E5%85%A5%E9%97%A8-12 iOS 6 Passbook 入门 1/ ...

  7. windows程序设计(二)

    MFC架构组成 1.CWinApp的派生类 2.必须在全局区定义一个派生类的对象 3.在CWinApp派生类内必须要有InitInstance虚函数的重写函数 在MFC软件工程以App类中的InitI ...

  8. Air打包exe

    1.用flash创建一个airtest.fla,发布目标选择为AIR.ctrl+enter会得到如下文件: 2.把flex sdk的bin中找到adl.exe,复制过来,放置到:项目目录\bin\ad ...

  9. HDU 2609 How many

    最小表示法+Map或者字典树,最小表示法找了个模板,还没学习呢... #include<cstdio> #include<cstring> #include<cmath& ...

  10. hb_gui配置heartbeat做MariaDB的高可用

    系统平台:CentOS release 6.5 (Final) Kernel:2.6.32-431.el6.x86_64 一.启动hb_gui hb_gui & 添加资源组 添加MySQL_I ...