D. Watch the Videos

简介: D. Watch the Videos

观察找规律

最大的和二分最小的,然后交替相邻,看是否合法

找到最长的合法段

答案就是总长度减去合法段加上原先的长度


#include<bits/stdc++.h>
#define debug1(a) cout<<#a<<'='<< a << endl;
#define debug2(a,b) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<endl;
#define debug3(a,b,c) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<endl;
#define debug4(a,b,c,d) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<endl;
#define debug5(a,b,c,d,e) cout<<#a<<" = "<<a<<"  "<<#b<<" = "<<b<<"  "<<#c<<" = "<<c<<"  "<<#d<<" = "<<d<<"  "<<#e<<" = "<<e<<endl;
#define debug0(x) cout << "debug0: " << x << endl
#define fr(t, i, n)for (long long i = t; i < n; i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fi first
#define se second
#define int long long
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<LL,LL> PLL;
//#pragma GCC optimize(3,"Ofast","inline")
//#pragma GCC optimize(2)
const int N = 2e5+10;
int a[N];
int n,v;
bool check(int x)
{
    int l = 1,r = x;
    while(l < r)
    {
        //debug2(l,r);
        if(a[l] + a[r] > v)return false;
        r --;
        if(l < r && a[l] + a[r] > v)return false;
        l ++;
    }
    return true;
}
void solve() 
{
    cin >> n >> v;
    int sum = 0;
    for(int i = 1;i <= n;i ++){
        cin >> a[i];
        sum += a[i];
    }
    
    sort(a+1,a+n+1);
    
    int l = 1,r = n;
    int mid;
    while(l < r)
    {
        mid = l+r+1>> 1;
        //debug3(l,r,mid);
        if(check(mid))l = mid;
        else r = mid-1;
        
    }
    
    cout << sum + n - l + 1<< endl;
}
signed main()
{
    /*
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    */
    int T = 1;//cin >> T;
    while(T--){
        solve();
    }
    return 0;
}


相关文章
|
10月前
|
JavaScript
document load 和 document ready 有什么区别
document load 和 document ready 有什么区别
194 0
|
10月前
|
JavaScript
鬼火起~为什么报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the
鬼火起~为什么报错[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the
|
9月前
|
JavaScript 前端开发
load、$(document).ready、DOMContentLoaded的区别
load、$(document).ready、DOMContentLoaded的区别
166 3
|
9月前
|
JavaScript 前端开发
document load 和 document ready 的区别
document load 和 document ready 的区别
|
10月前
|
JavaScript 前端开发 UED
深入理解 Document Load 和 Document Ready 的区别
深入理解 Document Load 和 Document Ready 的区别
131 0
|
资源调度
vue3 + ts:watch(immediate、deep、$watch)
vue3 + ts:watch(immediate、deep、$watch)
245 0
vue3 + ts:watch(immediate、deep、$watch)
|
编解码 区块链 流计算
[译]The Ogg Skeleton Metadata Bitstream
Ogg对它所携带的内容一无所知,而是将其留给每个编解码器的媒体映射来声明和描述自己。在Ogg级别上没有关于封装在Ogg物理比特流中的内容轨道的元信息。如果您没有所有可用的解码器库,而只是想解析一个Ogg文件以找出封装的数据类型(例如 nix下的“ file”命令来确定它是什么文件),则这尤其成问题。 (例如,通过魔术数字),或者想要寻求时间偏移而不必解码数据(例如在仅提供Ogg文件及其部分内容的Web服务器上)。
95 0
|
缓存 JavaScript 开发者
watch,commputed,methods 的对比|学习笔记
快速学习 watch,commputed,methods 的对比
122 0
|
JavaScript
【解决方案】[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the pa
【解决方案】[Vue warn]: Avoid mutating a prop directly since the value will be overwritten whenever the pa
1857 0
|
iOS开发 开发者
watch OS 6发布:Apple Watch终于成年了
Apple Watch自诞生之日起,如今已经有四个年头,在此期间产品的演变经历了从依赖iPhone到独立成单品的缓慢又稳定的发展过程。
1222 0