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;
}


相关文章
|
2月前
|
JavaScript 前端开发 Java
操作dome5
操作dome5
37 2
|
资源调度
vue3 + ts:watch(immediate、deep、$watch)
vue3 + ts:watch(immediate、deep、$watch)
207 0
vue3 + ts:watch(immediate、deep、$watch)
|
Web App开发 JavaScript 前端开发
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled. Please enable it to continue 这个错误提示表明目标网页要求启用JavaScript才能正常工作,而默认情况下,Selenium WebDriver是启用JavaScript的。如果遇到此错误,请按照以下步骤尝试解决问题
746 0
Selenium使用中报错:We\'re sorry but hr-frontend-v2 doesn\'t work properly without JavaScript enabled
|
编解码 区块链 流计算
[译]The Ogg Skeleton Metadata Bitstream
Ogg对它所携带的内容一无所知,而是将其留给每个编解码器的媒体映射来声明和描述自己。在Ogg级别上没有关于封装在Ogg物理比特流中的内容轨道的元信息。如果您没有所有可用的解码器库,而只是想解析一个Ogg文件以找出封装的数据类型(例如 nix下的“ file”命令来确定它是什么文件),则这尤其成问题。 (例如,通过魔术数字),或者想要寻求时间偏移而不必解码数据(例如在仅提供Ogg文件及其部分内容的Web服务器上)。
63 0
- Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as <script>, as t
vue.js报错如下: - Templates should only be responsible for mapping the state to the UI. Avoid placing tags with side-effects in your templates, such as , as they will not be parsed.
5646 1
|
JavaScript 前端开发 API
Reading files in JavaScript using the File APIs
Reading files in JavaScript using the File APIs By Eric Bidelman Published: June 18th, 2010Comments: 273 Introduction HTML5 finally provide...
1012 1
|
Web App开发 JavaScript 前端开发
Is server side rendering a good choice for React application
Single page application like react provides a wonderful user experience, however, it comes with two issues: For user who accesses the website at first time, there is no cache of javascript files in
1524 0