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


相关文章
Custom directive is missing corresponding SSR transform and will be ignored.
Custom directive is missing corresponding SSR transform and will be ignored.
49 0
|
资源调度
vue3 + ts:watch(immediate、deep、$watch)
vue3 + ts:watch(immediate、deep、$watch)
191 0
vue3 + ts:watch(immediate、deep、$watch)
|
Windows
DTDragDropFile UE Drag the system file to the window Plug-in Description
DTDragDropFile UE Drag the system file to the window Plug-in Description
65 0
Anaconda Navigator:could not find or load the QT platform plugin &quot;window in&quot;
Anaconda Navigator:could not find or load the QT platform plugin &quot;window in&quot;
225 0
Anaconda Navigator:could not find or load the QT platform plugin &quot;window in&quot;
【hacker的错误集】DeprecationWarning: find_element_by_* commands are deprecated.
DeprecationWarning: find_element_by_* commands are deprecated. Please use find_element() instead。依旧是使用单词意思分析报错原因
137 0
【hacker的错误集】DeprecationWarning: find_element_by_* commands are deprecated.
|
缓存 JavaScript 开发者
watch,commputed,methods 的对比|学习笔记
快速学习 watch,commputed,methods 的对比
104 0
|
iOS开发 开发者
watch OS 6发布:Apple Watch终于成年了
Apple Watch自诞生之日起,如今已经有四个年头,在此期间产品的演变经历了从依赖iPhone到独立成单品的缓慢又稳定的发展过程。
1198 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.
5627 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...
1007 1