3.23

原题链接

题外话

今天心情还是挺复杂的, 第一道由我名字命名的题(有点小激动。。) , 但是自己的脑袋转的不够快啊(吐血), 一个二分题,都想不出来, 十分尴尬

题意

中文字, 不说了

思路

因为要找到最大的组牌数量, 必然会和万能牌产生联系,所以首先考虑,万能牌和最后组出来的牌数量的关系,设万能牌数量为x , 最后组出来的牌数量是 y
- 如果万能牌的数量大于等于最后组出来的数量的话, 也就是说最多能用y张万能牌
- 反之,最多能用x张万能牌
接着我们考虑每种牌和上面我们定下来的最后的牌数的关系,设每种牌为ai
- 如果ai >=y ,不用考虑 , 足够使用的了
- 反之, 因为ai不够用, 所以我们要用万能牌 来补充,然后判断y在满足所有ai<x 的情况后,是否还是正数(意味着可以实现,反之不行)

代码

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define iinf 0x3f3f3f3f
#define linf (1ll<<60)
#define eps 1e-8
#define maxn 1000010
#define maxe 1000010
#define cl(x) memset(x,0,sizeof(x))
#define rep(i,a,b) for(i=a;i<=b;i++)
#define drep(i,a,b) for(i=a;i>=b;i--)
#define em(x) emplace(x)
#define emb(x) emplace_back(x)
#define emf(x) emplace_front(x)
#define fi first
#define se second
#define de(x) cerr<<#x<<" = "<<x<<endl
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll; 

ll read(ll x=0)
{
    ll c, f(1);
    for(c=getchar();!isdigit(c);c=getchar())if(c=='-')f=-f;
    for(;isdigit(c);c=getchar())x=x*10+c-0x30;
    return f*x;
}
ll n , k ;
int ar[1000010];
int  br[100010];
ll res =0 ;
bool check ( ll mid ){
	ll ans = min(mid, k);
	for(int i=0 ;i<n;i++){
		if(ar[i] < mid){
			ans -= mid - ar[i];
		}
		if(ans < 0)return false;
	}return true ;
}
int main()
{
   
	n =read() , k =read();
	for(int i=1 ;i<=n;i++)cin >>ar[i];
	for(int i=1 ;i<=k;i++)cin >>br[i];
	for(int i=1 ;i<=k;i++){
		int l =1 , r =n;
		while(l<=r){
			int mid = (l+r)>>1;
			if(ar[mid]< br[i]){
				l = mid +1 ;
			}
			else r =mid -1 ;
		}
		if(ar[l] !=br[i])cout<<-1 <<" ";
		else cout<<l <<" ";
	}
    return 0;
}

posted @ 2020-03-23 19:37  dsrcis  阅读(138)  评论(0编辑  收藏  举报