题目: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. SQL Server自动化运维系列 - 多服务器数据收集和性能监控

    需求描述 在生产环境中,很多情况下需要采集数据,用以定位问题或者形成基线. 关于SQL Server中的数据采集有着很多种的解决思路,可以采用Trace.Profile.SQLdiag.扩展事件等诸多 ...

  2. java中collection、map、set、list简介 (转)

    Collection接口  Collection是最基本的集合接口,一个Collection代表一组Object,即Collection的元素(Elements).一些Collection允许相同的元 ...

  3. iOS多线程--NSOperation

    NSOperation是基于GCD的一套多线程实现方案,和GCD一样,线程的生命周期是由系统来自动管理的,不用像NSThread和Pthread一样让程序员手动管理.相对于GCD来说,它更加地面向对象 ...

  4. Library string Type

    The string type supports variable-length character strings.The library takes cares of managing memor ...

  5. C++中delete和delete[]的使用

    偶然的机会要使用到动态分配整形数组,怎么删除new出来的东西一时有点模糊(也许一直就不知道),于是在VS上试了试(写代码时经常用这种方法去验证模凌两可的东西),总结出来有两点. 1.基本数据类型new ...

  6. skip跳跃表的实现

    skiplist介绍 跳表(skip List)是一种随机化的数据结构,基于并联的链表,实现简单,插入.删除.查找的复杂度均为O(logN).跳表的具体定义, 跳表是由William Pugh发明的, ...

  7. c++ primer复习(四)

    1 标准库容器 顺序容器:vector.list.deque 容器适配器:stack.queue.priority_queue 2 容器元素类型约束: 容器元素类型必须支持复制和赋值,因为容器存放的都 ...

  8. Python没有执行__init__

    疑惑 提出问题 前天同事问我一个问题,为什么这个脚本中的没有调用A 的__init__.脚本如下: class A(object): def __init__(self, *args, **kwarg ...

  9. ubuntu ssh安装

    参考 http://www.linuxidc.com/Linux/2010-02/24349.htm  文章很不错!! ssh   登录名@ip地址 , 如果提示验证key can't be esta ...

  10. Ubuntu下Java环境配置

    Oracle Java安装: 通过以下命令进行安装: sudo add-apt-repository ppa:webupd8team/java sudo apt-get update sudo apt ...