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


相关文章
|
8月前
|
JavaScript 前端开发
load、$(document).ready、DOMContentLoaded的区别
load、$(document).ready、DOMContentLoaded的区别
144 3
|
前端开发 JavaScript
[Bugfix]it looks like you called `mount()` without a global document being loade
jest测试react组件时尝试获取mount组件报错,并无法进行测试,解决过程记录。
116 1
|
缓存 JavaScript 开发者
watch,commputed,methods 的对比|学习笔记
快速学习 watch,commputed,methods 的对比
121 0
|
iOS开发 开发者
watch OS 6发布:Apple Watch终于成年了
Apple Watch自诞生之日起,如今已经有四个年头,在此期间产品的演变经历了从依赖iPhone到独立成单品的缓慢又稳定的发展过程。
1216 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.
5675 1
Microsoft BuleHat 2018 Videos and Slides
https://www.youtube.com/watch?v=jxve5hrtwnI&feature=youtu.
1889 0
|
前端开发 JavaScript
|
人工智能
Codeforces 768A Oath of the Night&#39;s Watch
A. Oath of the Night's Watch time limit per test:2 seconds memory limit per test:256 megabytes input:standard input outp...
829 0