K - Video Reviews Gym - 101755K (二分)

The studio «Lodka Gaming» is engaged in advertising of their new game «.C.O.N.T.E.S.T: Unexpected Behaviour». The studio's marketer is planning to communicate with n videobloggers one by one (in the predetermined order, starting from the 1-st and ending with the n-th), offering them to record a video review on the game. All people are different and videobloggers are as well, therefore the i-th videoblogger will record a review in two cases: either he is interested in this game, or there are already at least ai video reviews on this game.

The studio wants to have at least m video reviews in the Internet. The game designer of «Lodka Gaming» understands these video reviews possibly would not appear by themselves, so he wants to convince some video bloggers that they are actually interested in this game. Which minimal number of videobloggers are needed to be convinced?

Input

The first line contains two integers n and m (1 ≤ n ≤ 200000, 1 ≤ m ≤ n) — the number of videobloggers and the required number of video reviews.

The second line contains n integers ai (0 ≤ ai ≤ 200000) — the minimal number of video reviews that should appear in the Internet so that the i-th videoblogger will record a review in case he is not interested in the game.

Output

Output a single integer — the minimal number of videobloggers who have to be convinced to record a video review on the game in order to achieve at least m total video reviews in the Internet.

Examples

Input

7 4
2 1 3 3 4 2 3

Output

1

Input

7 4
2 1 3 3 4 3 2

Output

2

题意:一家公司想让a个人给他们的产品评论,所以依次去找这a个人,第i个人会评论当且仅当已经有ni个人评论或他确实对这个产品感兴趣,但是这a个人都不对这个产品感兴趣,问这个公司至少要说服几个人对该产品该兴趣才能至少收到b个人的评论

假如你要强迫人肯定要强迫最前边的,因为说服一个人对评论数贡献为1​,而提早做贡献可以带来更多的贡献

对于这种情况,有种强大的方法:二分(二分要强迫的人数)
二分的好处就是简化复杂度,用假设的已知代替未知

对于求一个最多或最少的问题,通常可以用二分来简单地解决

像这题,用二分得到确切的强迫次数,那么就可以直接从前往后遍历了
代码:


//Full of love and hope for life

#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <queue>
#include <map>
#define inf 0x3f3f3f3f3f3f3f3f
//https://paste.ubuntu.com/

using namespace std;

typedef long long ll;
const int maxn=2e5+10;

ll a,b;
ll n[maxn];

bool check(ll k){
    ll ans=0;
    for(int i=0;i<a;i++){
    if(ans>=n[i]){//如果可以直接聘请
        ans++;
    }
    else if(k){//如果不能够聘请,且有贿赂名额
        k--;
        ans++;
    }
    if(ans==b){//够人数return
        return true;
    }
   }
   return false;
}

int main(){
    ll sum;
    cin >> a >> b;
    for(int i=0;i<a;i++){//最好从0开始,不然要特判特殊情况
        cin >> n[i];
    }
    int l=0;
    int r=a;
    while(l<=r){//二分
        int mid=(l+r)/2;
        if(check(mid)){
            r=mid-1;
            sum=mid;
        }
        else{
            l=mid+1;
        }
    }
    cout << min(sum,b);
    return 0;
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
IoT是物联网(Internet of Things)的缩写,是指通过物理设备和传感器等技术将物理世界与互联网连接起来的概念。Sensor是传感器的意思,是一种能够感知和测量周围环境参数的装置。Gym master是指健身房的管理系统。那么,"IoT-Sensor-Gym-Master"指的是结合物联网、传感器技术和健身房管理系统的项目或产品。 在这个项目中,通过在健身房内部部署各种类型的传感器设备,可以实时感知和监控健身房的各种环境参数以及用户的行为。例如,可以使用体感传感器来监测用户的运动状态,心率传感器来监测用户心率变化,温湿度传感器来监测环境的温度和湿度等等。这些传感器会把收集到的数据通过物联网技术传输到云端服务器进行处理和分析。 在云端服务器上,会有一个健身房管理系统,通过对接收到的传感器数据进行分析和处理,可以提供各种健身相关的功能和服务。例如,可以根据用户的运动状态自动调整健身器材的强度,提供个性化的健身方案;还可以通过用户心率数据实时预警和监控用户的身体状况,保证用户的健康安全;同时,还可以通过温湿度传感器来实时监测健身房的环境,保证用户的舒适度。 总之,"IoT-Sensor-Gym-Master"项目结合了物联网、传感器技术和健身房管理系统的优势,将智能化和个性化服务引入健身领域,为用户提供更好的健身体验和管理服务。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZZ --瑞 hopeACMer

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值