首页 > 其他分享 >Codeforces Global Round 17 C

Codeforces Global Round 17 C

时间:2022-10-15 22:22:52浏览次数:36  
标签:cnt const 17 int Global Codeforces long mid

C. Keshi Is Throwing a Party

我们显然可以二分答案
我们的最优解情况就是从小到大的选择
要是a[i]>=x-cnt-1(还要减去自身)&&b[i]>=cnt我们就把他算进去
这样肯定是最优的 当然从大到小也可以

#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+10;
const int M = 998244353;
const int mod = 20220911;
#define int long long
int up(int a,int b){return a<0?a/b:(a+b-1)/b;}
#define endl '\n'
#define all(x) (x).begin(),(x).end()
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define _ 0
#define pi acos(-1)
#define INF 0x3f3f3f3f3f3f3f3f
#define fast ios::sync_with_stdio(false);cin.tie(nullptr);
int n,a[N],b[N];
bool check(int x){
    int cnt=0;
    for(int i=1;i<=n;i++){
        if(cnt<=b[i]&&x-cnt-1<=a[i])++cnt;
        if(cnt==x)return 1;
    }
    return 0;
}
void solve() {
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i]>>b[i];
    int l=1,r=n;
    while(l<r){
        int mid=l+r+1>>1;
        if(check(mid))l=mid;
        else r=mid-1;
    }
    cout<<l<<endl;
}
signed main(){
    fast
    int t;t=1;cin>>t;
    while(t--) {
        solve();
    }
    return ~~(0^_^0);
}

标签:cnt,const,17,int,Global,Codeforces,long,mid
From: https://www.cnblogs.com/ycllz/p/16795195.html

相关文章

  • [Editorial] Codeforces Contest 878D
    中文题面好题,写篇题解记录一下。首先如果值域是\(\{0,1\}\),那么直接搞一个bitset维护一下。由于只有\(2^k\)中不同的初始取值,所以维护\(2^k\)长度即可。然后考虑值......
  • Card Deck CodeForces - 1492B
    CardDeckCodeForces-1492B你有一副n张牌,你想把它重新排序为一副新的。每张卡都有一个介于1和n之间的值,该值等于pi。所有pi两两不同。牌组中的牌是从下到上......
  • 617. 合并二叉树
    /***Definitionforabinarytreenode.*structTreeNode{*intval;*TreeNode*left;*TreeNode*right;*TreeNode():val(0),left(......
  • 「CF1710D」Recover the Tree
    \(\texttt{「CF1710D」RecovertheTree}\)\(\texttt{Solution}\)考虑好区间\(I_1,I_2(I_1\capI_2\not=\empty)\),\(I_1\capI_2\)和\(I_1\cupI_2\)都是好区间。于......
  • 「题解」Codeforces 441E Valera and Number
    感觉是dp好题啊!这里令\(n\)作为原题面中的\(k\).方法一:我认为的通过常规思路想出来的做法。正常思路是设\(f_{i,x}\)表示操作了\(i\)步得到\(x\)的概率。但是......
  • 「题解」Codeforces 1442E Black, White and Grey Tree
    怎么题解都是清一色的dp啊我们需要做的是,从简单的情景出发,找到性质。不难想到的是,相邻的同色节点可以合并到一起,因为如果无论何种最优操作,总是可以将这个同色连通块里......
  • 代码随想录训练营|Day 25|216,17
    216.CombinationSumIIIFindallvalidcombinationsof k numbersthatsumupto n suchthatthefollowingconditionsaretrue:Onlynumbers 1 through ......
  • Codeforces Round #747 (Div. 2) D // 扩展域并查集
    题目来源:CodeforcesRound#747(Div.2)D-TheNumberofImposters题目链接:Problem-D-Codeforces题意有\(n\)个人,每个人拥有\(imposter\)或\(crewmate\)的身份......
  • Linux系统编程17-opendir,readdir与closedir.md
    #include<sys/types.h>#include<dirent.h>DIR*opendir(constchar*name);作用:打开一个目录参数:-name:需要打开的目录流返回值:......
  • Educational Codeforces Round 117 D
    D.X-MagicPair显然对于两个操作可以一眼识别是辗转相减可是我们怎么利用这个信息我们可以发现如果a>b;我们将更小的b替换成|a-b|那么我们显然又转回来了我们考虑......