Loading

代码-CF1469F Power Sockets

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define x first
#define y second
#define bg begin()
#define ed end()
#define pb push_back
#define mp make_pair
#define sz(a) int((a).size())
#define R(i,n) for(int i(0);i<(n);++i)
#define L(i,n) for(int i((n)-1);i>=0;--i)
const int iinf=0x3f3f3f3f;
const ll linf=0x3f3f3f3f3f3f3f3f;

//Data
const int N=2e5,D=5e5;
int n,m,a[N]; ll w[D];

//Main
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin>>n>>m;
    R(i,n) cin>>a[i];
    sort(a,a+n,greater<int>());
    ll tot=0; int ns=iinf;
    w[0]=1,w[1]=-1;
    for(int d=0,i=0;d<D-3;++d){
        w[d+1]+=w[d],tot+=w[d];
        if(tot+w[d+1]>=m){ns=d+1; break;}
        while(i<n&&w[d]){
            int l=(a[i]-1)>>1,r=a[i]-1-l; ++i;
            w[d+2]+=2,--w[d+2+l],--w[d+2+r];
            --w[d],--tot;
        }
    }
    if(ns==iinf) cout<<-1<<'\n';
    else cout<<ns<<'\n';
    return 0;
}

posted @ 2020-12-29 15:33  George1123  阅读(15)  评论(0编辑  收藏  举报