結果

問題 No.3808 Welcome to Mid Difficulty Problems
コンテスト
ユーザー eQe
提出日時 2026-11-20 22:30:26
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -fplugin=/usr/lib/yukicoder/noavx512-gcc15.so -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 4,669 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 4,250 ms
コンパイル使用メモリ 365,524 KB
実行使用メモリ 46,544 KB
最終ジャッジ日時 2026-11-20 22:30:35
合計ジャッジ時間 7,891 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 15 WA * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

/*
#include<kyopro/master>
void self::main(){
  LL(N,T);
  VV(N,a,b);
  
  ll M=zip(a).size();
  vec<vec<ll>>g(M);
  fo(i,N)g[a[i]].eb(b[i]);
  
  vec<ll>v2,v1;
  fo(x,M){
    sort(g[x]);
    v2.eb(g[x][0]);
    g[x].pop_front();
    v1^=g[x];
  }
  sort(v2);
  sort(v1);
  zeta(v2);
  zeta(v1);
  
  ll ans=0;
  fo(k,v2.size()){
    ll t2=v2.segment_sum(0,k);
    if(t2>T)break;
    ll t1=T-t2;
    
    ll l=binary_search_last_true(0,v1.size()+1,[&](ll l){
      return v1.segment_sum(0,l)<=t1;
    });
    amax(ans,k*2+l);
  }
  pp(ans);
}
*/

#include<bits/stdc++.h>
using namespace std;
namespace self{void main();void sub();void pp(auto&&...a);void ppe(auto&&...a);}
int main(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);self::main();}
#define eb emplace_back
#define RD(T,...) T __VA_ARGS__;lin(__VA_ARGS__)
#define LL(...) RD(ll,__VA_ARGS__)
#define RDVV(T,n,...) vec<T>__VA_ARGS__;fe(refs(__VA_ARGS__),e)e.get().resizes(n);vin(__VA_ARGS__)
#define VV(n,...) RDVV(ll,n,__VA_ARGS__)
#define fo(i,...) for(auto[i,i##stop,i##step]=for_range<ll>(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
namespace self{
using ll=long long;
constexpr auto refs(auto&...a){return array{ref(a)...};}
template<class T>constexpr auto for_range(T s,T b){T a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
void lin(auto&...a){(cin>>...>>a);}
void vin(auto&...a){fo(i,(a.size()&...))(cin>>...>>a[i]);}
constexpr auto abs(auto x){return x<0?-x:x;}
bool amax(auto&a,const auto&b){return a<b?a=b,1:0;}
ll binary_search_last_true(ll o,ll x,auto&&f){while(abs(o-x)>1)(f((o+x)/2)?o:x)=(o+x)/2;return o;}
template<class F=less<>>decltype(auto)sort(auto&&a,F f={}){ranges::sort(a,f);return a;}
template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;
}
namespace self{
template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int depth=0;
template<vectorial V>constexpr int depth<V> =depth<typename V::value_type>+1;
template<class T>struct core_t_helper{using type=T;};
template<class T>using core_t=core_t_helper<T>::type;
template<class V>struct vec;
template<int D,class T>struct hvec_helper{using type=vec<typename hvec_helper<D-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int D,class T>using hvec=hvec_helper<D,T>::type;
template<class V>struct vec:vector<V>{
  static constexpr int D=depth<V>+1;
  using C=core_t<V>;
  using vector<V>::vector;
  void resizes(const auto&...a){if constexpr(sizeof...(a)==D)*this=make(a...,C{});else{ }}
  static auto make(ll n,const auto&...a){
    if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
    else { }
  }
  auto&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;}
  ll size()const{return vector<V>::size();}
  auto&emplace_back(auto&&...a){vector<V>::emplace_back(std::forward<decltype(a)>(a)...);return*this;}
  auto pop_front(){auto r=*this->begin();this->erase(this->begin());return r;}
  auto segment_sum(ll a,ll b)const{assert(0<=a&&a<=b&&b<=size());C res=0;if(b)res+=(*this)[b-1];if(a)res-=(*this)[a-1];return res;}
  template<class F=less<>>vec stable_sort(F f={})const{vec v=*this;ranges::stable_sort(v,f);return v;}
  template<class F=less<>>auto sort_from(F f={})const{
    vec<ll>o(size());
    std::iota(o.begin(),o.end(),0);
    return o.stable_sort([&](ll i,ll j){return f((*this)[i],(*this)[j]);});
  }
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
template<class F,class...A>auto zip_by(F f,A&...a){
  auto v=(a^...);
  auto o=v.sort_from(f);
  vec<ll>z(v.size());
  decltype(v)u;
  fe(o,i){
    if(u.empty()||f(u.back(),v[i]))u.push_back(v[i]);
    z[i]=u.size()-1;
  }
  ll i=0;
  ([&](auto&x){fe(x,e)e=z[i++];}(a),...);
  return u;
}
auto zip(auto&...a){return zip_by(less<>{},a...);}
template<vectorial V>void zeta(V&&v){if constexpr(depth<remove_cvref_t<V>>>1){ }fo(i,v.size()-1)v[i+1]+=v[i];}
}
void self::pp(auto&&...a){const char*c="";((cout<<c<<a,c=" "),...);cout<<'\n';}
void self::main(){
  LL(N,T);
  VV(N,a,b);

  ll M=zip(a).size();
  vec<vec<ll>>g(M);
  fo(i,N)g[a[i]].eb(b[i]);

  vec<ll>v2,v1;
  fo(x,M){
    sort(g[x]);
    v2.eb(g[x][0]);
    g[x].pop_front();
    v1^=g[x];
  }
  sort(v2);
  sort(v1);
  zeta(v2);
  zeta(v1);

  ll ans=0;
  fo(k,v2.size()){
    ll t2=v2.segment_sum(0,k);
    if(t2>T)break;
    ll t1=T-t2;

    ll l=binary_search_last_true(0,v1.size()+1,[&](ll l){
      return v1.segment_sum(0,l)<=t1;
    });
    amax(ans,k*2+l);
  }
  pp(ans);
}
0