题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFnoi%E8%80%83%E5%90%8E%E6%AC%A2%E4%B9%90%E8%B5%9B%29/%E4%B9%8C%E9%B8%A6%E5%96%9D%E6%B0%B4

题解:真是一道神题!考场上绝对想不到标算orz!

题解写在代码注释里

代码:

 #include<cstdio>

 #include<cstdlib>

 #include<cmath>

 #include<cstring>

 #include<algorithm>

 #include<iostream>

 #include<vector>

 #include<map>

 #include<set>

 #include<queue>

 #include<string>

 #define inf 1000000000

 #define maxn 100000+5

 #define maxm 500+100

 #define eps 1e-10

 #define ll long long

 #define pa pair<int,int>

 #define for0(i,n) for(int i=0;i<=(n);i++)

 #define for1(i,n) for(int i=1;i<=(n);i++)

 #define for2(i,x,y) for(int i=(x);i<=(y);i++)

 #define for3(i,x,y) for(int i=(x);i>=(y);i--)

 #define mod 1000000007

 using namespace std;

 inline int read()

 {

     int x=,f=;char ch=getchar();

     while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}

     while(ch>=''&&ch<=''){x=*x+ch-'';ch=getchar();}

     return x*f;

 }
int n,m,h,s[maxn],a[maxn],b[maxn],id[maxn];
inline void add(int x,int y){for(;x<=n;x+=x&(-x))s[x]+=y;}
inline int sum(int x){int t=;for(;x;x-=x&(-x))t+=s[x];return t;}
inline bool cmp(int x,int y){return b[x]==b[y]?x<y:b[x]<b[y];} int main() { freopen("input","r",stdin); freopen("output.txt","w",stdout); n=read();m=read();h=read();
for1(i,n)a[i]=read();
for1(i,n)
{
int x=read();
if(a[i]<=h)b[i]=(h-a[i])/x+;//b[i]表示该点最多可以被饮几次水
if(b[i]>)add(i,);id[i]=i;
}
//可以证明,最后的答案一定是某个b[i],所以我们按b[i]从小到大处理
sort(id+,id+n+,cmp);
int now=,pos=,ans=,st=n+;//now 表示当前的趟数
//for1(i,n)cout<<i<<' '<<id[i]<<' '<<b[i]<<endl;
for1(i,n)if(b[id[i]]){st=i;break;}
for2(i,st,n)
{
while(now<=m)
{
int t=sum(n)-sum(pos);
if(ans+t<b[id[i]])ans+=t,now++,pos=;//如果可以走完这一趟
else break;
}
if(now>m)break;
int l=pos,r=n,t=sum(pos);
while(l<=r)
{
int mid=(l+r)>>;
if(sum(mid)-t+ans>=b[id[i]])r=mid-;else l=mid+;
}//二分到下一个点
ans=b[id[i]];pos=l;
for(;b[id[i]]==b[id[i+]];i++)add(id[i],-);//去除不能再次饮水的点
add(id[i],-);
}
printf("%d\n",ans); return ; }

Beta Round #9 (酱油杯noi考后欢乐赛)乌鸦喝水的更多相关文章

  1. Beta Round #9 (酱油杯noi考后欢乐赛)随机数生成器

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  2. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ和他的小伙伴们

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  3. Beta Round #9 (酱油杯noi考后欢乐赛)PLQ的寻宝

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  4. Beta Round #9 (酱油杯noi考后欢乐赛)最大伤害

    题目:http://www.contesthunter.org/contest/Beta%20Round%20%EF%BC%839%20%28%E9%85%B1%E6%B2%B9%E6%9D%AFno ...

  5. 洛谷---小L和小K的NOIP考后放松赛

    链接: https://www.luogu.org/contestnew/show/11805?tdsourcetag=s_pcqq_aiomsg 题解: 没人过的题我就没看 t2: 考虑每个点是朋友 ...

  6. Codeforces Beta Round #22 (Div. 2 Only)

    Codeforces Beta Round #22 (Div. 2 Only) http://codeforces.com/contest/22 A 水题 #include<bits/stdc+ ...

  7. Codeforces Beta Round #16 (Div. 2 Only)

    Codeforces Beta Round #16 (Div. 2 Only) http://codeforces.com/contest/16 A 水题 #include<bits/stdc+ ...

  8. Codeforces Beta Round #12 (Div 2 Only)

    Codeforces Beta Round #12 (Div 2 Only) http://codeforces.com/contest/12 A 水题 #include<bits/stdc++ ...

  9. Codeforces Beta Round #57 (Div. 2)

    Codeforces Beta Round #57 (Div. 2) http://codeforces.com/contest/61 A #include<bits/stdc++.h> ...

随机推荐

  1. HTML<label> 标签的 for 属性

    定义和用法 for 属性规定 label 与哪个表单元素绑定. 隐式和显式的联系 标记通常以下面两种方式中的一种来和表单控件相联系:将表单控件作为标记标签的内容,这样的就是隐式形式,或者为 <l ...

  2. Linux 经典面试题

    [Linux  经典面试题] 1. 在Linux系统中,以 文件 方式访问设备 . 2. Linux内核引导时,从文件 /etc/fstab 中读取要加载的文件系统. 3. Linux文件系统中每个文 ...

  3. 深入了解float

    1.float的历史   初衷是为了图片的文字环绕,将img设置float 2.破坏性与包裹性  a.父元素没有设置高度,内部元素浮动后,服务元素的高度被破坏了,可以将其父元素设置overflow:h ...

  4. php发送http请求

    http请求有get,post. php发送http请求有三种方式[我所知道的有三种,有其他的告诉我]. file_get_contents();详情见:http://www.cnblogs.com/ ...

  5. Delphi接口

    program Demo1; { Create Date: 2014-06-29 Author: P.S.M 1.接口Demo1 } {$APPTYPE CONSOLE} uses SysUtils; ...

  6. IIS日志分析

    发现一个强大的图形化IIS日志分析工具——Log Parser Studio,下面分享一个实际操作案例. 1. 安装Log Parser Studio a) 需要先安装Log Parser,下载地址: ...

  7. 使用 windows 计划任务播放音乐文件

    这个问题网上可以搜到很多答案,但都有一些小细节没有交代,而我平时又很少使用计划任务,所以配置中出了点问题,特此备注. 1.播放器 检查当前系统下目标文件的默认播放器是什么,并且确保可以运行. 比如首次 ...

  8. android中LayoutInflater详解与使用

    android的LayoutInflater用来得到一个布局文件,也就是xxx.xml,而我们常用的findviewbyid是用来取得布局文件里的控件或都布局.inflater即为填充的意思,也就是说 ...

  9. OC 之 const

    1. 修饰变量 一般设置传参数的时候 若设置为const, 则在调用过程中不允许修改参数值;(readonly) // *前const: 不能通过指针, 改变p指向的值 const int *p = ...

  10. Docker的安装及简单使用

    1.  Docker的安装 (这里的“安装docker”其实就是安装Docker Engine) $ sudo apt-get intasll docker.io note: apt-get是ubun ...