LOADING

加载过慢请开启缓存,浏览器默认开启

daily 2

2023/6/1 daily

CF 650B

void solve(){
  int n,a,b,t;
  cin>>n>>a>>b>>t;
  string s;
  cin>>s;
  s='0'+s;
  vector<int>sum(n+1);
  for(int i=1;i<=n;++i){
    sum[i]=sum[i-1]+(s[i]=='w'?b+1:1);
  }
  auto calc=[&](int r){//r means left 
    for(int i=1;i<=r;++i){
        ll s1=sum[i]+sum[n]-sum[n-(r-i)];
        ll s2=min((i-1)*a*2+(r-i)*a,2*(r-i)*a+(i-1)*a);
        if(s1+s2<=t){
            return true;
        }
    }
    return false;
  };
  int l=0,r=n,ans=0;
  while(l<=r){
    int m=(l+r)>>1;
    if(calc(m)){
        ans=m;
        l=m+1;
    }else{
        r=m-1;
    }
  }
  cout<<ans<<'\n';
  return;
}

CF 633D

void solve(){
  int n;
  cin>>n;
  vector<int>a(n+1);
  map<int,int>mp;
  for(int i=1;i<=n;++i){
    cin>>a[i];
    mp[a[i]]++;
  }
  sort(a.begin()+1,a.end());
  int ans=mp[0];
  for(int i=1;i<=n;++i){
    for(int j=1;j<=n;++j){//start from the initial two elements
      if((i!=j)&&(a[i]!=0||a[j]!=0)){
        vector<int>cur;
        int cur1=a[i],cur2=a[j],cur_ans=2;
        mp[a[i]]--;
        mp[a[j]]--;
        cur.push_back(cur1);
        cur.push_back(cur2);
        while(1){
          if(mp[cur1+cur2]){
            mp[cur1+cur2]--;
            cur.push_back(cur1+cur2);
            swap(cur1,cur2);
            cur2=cur1+cur2;
            ++cur_ans;
          }else break;
        }
        ans=max(ans,cur_ans);
        for(int v:cur){
          mp[v]++;
        }
    }
  }
  }
  cout<<ans<<'\n';
  return;
}