zoukankan      html  css  js  c++  java
  • Educational Codeforces Round 75 (Rated for Div. 2)D(二分)

    #define HAVE_STRUCT_TIMESPEC
    #include<bits/stdc++.h>
    using namespace std;
    pair<int,int>a[200007];
    int n;
    long long s;
    bool check(int x){
    int num=0;
    long long sum=s;
    for(int i=n;i;--i){
    if(a[i].first>=x)
    ++num;
    else if(a[i].second>=x&&sum>=x-a[i].first){
    ++num;
    sum-=x-a[i].first;
    }
    }
    if(num>=n/2+1)
    return 1;
    return 0;
    }
    int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t;
    cin>>t;
    while(t--){
    cin>>n>>s;
    int x,y;
    for(int i=1;i<=n;++i){
    cin>>x>>y;
    a[i]={x,y};
    s-=x;
    }
    sort(a+1,a+1+n);
    int l=a[n/2+1].first,r=1e9;
    int ans=0;
    while(l<=r){
    int mid=(l+r)>>1;
    if(check(mid)){
    ans=mid;
    l=mid+1;
    }
    else
    r=mid-1;
    }
    cout<<ans<<" ";
    }
    return 0;
    }

    保持热爱 不懈努力 不试试看怎么知道会失败呢(划掉) 世上无难事 只要肯放弃(划掉)
  • 相关阅读:
    邻接矩阵
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
    LeetCode
  • 原文地址:https://www.cnblogs.com/ldudxy/p/11832569.html
Copyright © 2011-2022 走看看