結果
| 問題 | No.3537 Thank You! |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-11-24 22:37:42 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 93 ms / 2,000 ms |
| + 111µs | |
| コード長 | 22,206 bytes |
| 記録 | |
| コンパイル時間 | 5,410 ms |
| コンパイル使用メモリ | 402,016 KB |
| 実行使用メモリ | 9,908 KB |
| 最終ジャッジ日時 | 2026-11-24 22:37:53 |
| 合計ジャッジ時間 | 10,436 ms |
|
ジャッジサーバーID (参考情報) |
judge4_0 / judge2_0 |
(要ログイン)
| サブタスク | 配点 | 結果 |
|---|---|---|
| サブタスク1 | 30 % | AC * 21 |
| サブタスク2 | 70 % | AC * 15 |
| 合計 | 2.5 * 100% = 250 点 |
ソースコード
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
constexpr long long INF=2002002002002002002LL;
constexpr double PI=3.14159265358979323846;
constexpr long long dx[]={ 1, 0, -1, 0, 1, -1, -1, 1, 0};
constexpr long long dy[]={ 0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr string yesno[]={"No\n","Yes\n"};
constexpr char DRUL[]="DRUL";
constexpr unsigned long long TEN[]={1,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000,100000000000,1000000000000,10000000000000,100000000000000,1000000000000000,10000000000000000,100000000000000000,1000000000000000000,10000000000000000000ULL};
using ll=long long;
using ull=unsigned long long;
using mint=atcoder::modint998244353;
template<class T> using min_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class U,class V> pair<U,V> operator+(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first+rhs.first,lhs.second+rhs.second}; }
template<class U,class V> pair<U,V> operator-(const pair<U,V> &lhs, const pair<U,V> &rhs) { return {lhs.first-rhs.first,lhs.second-rhs.second}; }
template<class U,class V> pair<U,V> &operator+=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs+rhs; }
template<class U,class V> pair<U,V> &operator-=(pair<U,V> &lhs, const pair<U,V> &rhs) { return lhs=lhs-rhs; }
template<class T> pair<T,T> operator*(const pair<T,T> &lhs, const T &rhs) { return {lhs.first*rhs,lhs.second*rhs}; }
template<class T> pair<T,T> operator*(const T &lhs, const pair<T,T> &rhs) { return {lhs*rhs.first,lhs*rhs.second}; }
template<class T> pair<T,T> operator/(const pair<T,T> &lhs, const T &rhs) { return {lhs.first/rhs,lhs.second/rhs}; }
template<class T> T operator*(const pair<T,T> &lhs, const pair<T,T> &rhs) { return lhs.first*rhs.second-rhs.first*lhs.second; }
template<class T> inline T hypotsq(const pair<T,T> &p) { return p.first*p.first+p.second*p.second; }
template<class T> inline double hypot(const pair<T,T> &p) { return hypot<double>(p.first,p.second); }
template<class T> inline T hypotsq(T x, T y) { return x*x+y*y; }
template<class T> inline T hypotsq(T px, T py, T qx, T qy) { return hypotsq(qx-px,qy-py); }
template<class T> inline double hypot(T px, T py, T qx, T qy) { return hypot<double>(qx-px,qy-py); }
template<int M> istream &operator>>(istream &is, atcoder::static_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::static_modint<M> &x) { return os<<x.val(); }
template<int M> istream &operator>>(istream &is, atcoder::dynamic_modint<M> &x) { long long _x; is>>_x; x=_x; return is; }
template<int M> ostream &operator<<(ostream &os, const atcoder::dynamic_modint<M> &x) { return os<<x.val(); }
istream &operator>>(istream &is, __int128_t &x) { string S; is>>S; x=0; bool neg=false; for (auto &c : S) { if (c=='-') neg=true; else x=x*10+c-'0'; } if (neg) x=-x; return is; }
ostream &operator<<(ostream &os, __int128_t x) { if (x==0) return os<<0; if (x<0) os<<'-', x=-x; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S),end(S)); return os<<S; }
istream &operator>>(istream &is, __uint128_t &x) { string S; is>>S; x=0; for (auto &c : S) x=x*10+c-'0'; return is; }
ostream &operator<<(ostream &os, __uint128_t x) { if (x==0) return os<<0; string S; while (x) S.push_back('0'+x%10), x/=10; reverse(begin(S), end(S)); return os<<S; }
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p);
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p);
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t);
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t);
template<class T> istream &operator>>(istream &is, vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const vector<T> &v);
template<class T> ostream &operator<<(ostream &os, const optional<T> &x);
template<class U,class V> istream &operator>>(istream &is, pair<U,V> &p) { return is>>p.first>>p.second; }
template<class U,class V> ostream &operator<<(ostream &os, const pair<U,V> &p) { return os<<p.first<<' '<<p.second; }
template<class ...T> istream &operator>>(istream &is, tuple<T...> &t) { apply([&](auto &...args) { ((is>>args), ...); },t); return is; }
template<class ...T> ostream &operator<<(ostream &os, const tuple<T...> &t) { apply([&](auto &...args) { int n=0; ((os<<(n++?" ":"")<<args), ...); },t); return os;}
template<class T> istream &operator>>(istream &is, vector<T> &v) { for (auto &x : v) is>>x; return is; }
template<class T> ostream &operator<<(ostream &os, const vector<T> &v) { for (int i=0,s=(int)v.size();i<s;++i) os<<(i?" ":"")<<v[i]; return os; }
template<class T> ostream &operator<<(ostream &os, const set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const unordered_set<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const multiset<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const list<T> &v) { auto it=v.begin(); while (it!=v.end()) os<<*it++<<(it==v.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const stack<T> &v) { stack<T> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const queue<T> &v) { queue<T> u=v; while (!u.empty()) { os<<u.front(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T> ostream &operator<<(ostream &os, const deque<T> &v) { deque<T> u=v; while (!u.empty()) { os<<u.front(); u.pop_front(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U,class V> ostream &operator<<(ostream &os, const priority_queue<T,U,V> &v) { priority_queue<T,U,V> u=v; while (!u.empty()) { os<<u.top(); u.pop(); if (!u.empty()) os<<' '; } return os; }
template<class T,class U> ostream &operator<<(ostream &os, const map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T,class U> ostream &operator<<(ostream &os, const unordered_map<T,U> &m) { auto it=m.begin(); while (it!=m.end()) os<<(it->first)<<':'<<(it++->second)<<(it==m.end()?"":" "); return os; }
template<class T> ostream &operator<<(ostream &os, const optional<T> &x) { if (x.has_value()) return os<<x.value(); return os<<"-1"; }
template<class T,class U> inline T floor(const T &a, const U &b) { return a/b-(a%b && (a^b)< 0); }
template<class T,class U> inline T ceil (const T &a, const U &b) { return a/b+(a%b && (a^b)>=0); }
inline double radian(double deg) { return (PI/180.0)*deg; }
inline double degree(double rad) { return (180.0/PI)*rad; }
inline long long popcount(unsigned long long x) { return __builtin_popcountll(x); }
inline long long height(unsigned long long x) { if (x==0) return 0LL; return 64LL-__builtin_clzll(x); }
inline long long ctz(unsigned long long x) { return __builtin_ctzll(x); }
inline long long lsb(long long b) { return b&-b; }
template<class T> long long sgn(const T &x) { if (x<0) return -1; return x>0; }
template<class T> inline typename enable_if<is_integral_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a%b; if (res<0) res+=b; return res; }
template<class T> inline typename enable_if<is_floating_point_v<T>,T>::type rem(T a, T b) { assert(b>0); T res=a-floor(a/b)*b; if (res<0.0) res+=b; return res; }
template<class T> inline bool inlr(const T &l, const T &x, const T &r) noexcept { return (l<=x && x<r); }
template<class T> bool isinc(T first, T second) { return first<=second; }
template<class T,class ...Rest> bool isinc(T first, T second, const Rest ...rest) { return first<=second && isinc(second,rest...); }
long long safe_mul() noexcept { return 1LL; }
template<class ...Rest> long long safe_mul(long long a, Rest ...rest) noexcept { if (a==0LL) return 0LL; long long b=safe_mul(rest...); if (b==0LL) return 0LL; if (INF/a/b==0LL) return ((0LL<a)^(0LL<b) ? -INF : INF); return a*b; }
template<class T> void println(T item) { cout<<item<<'\n'; }
template<class T,class ...Rest> void println(T item, Rest ...rest) { cout<<item<<' '; println(rest...); }
template<class T> void dump(T item) { cerr<<item<<'\n'; }
template<class T,class ...Rest> void dump(T item, Rest ...rest) { cerr<<item<<' '; dump(rest...); }
long long safe_lcm(long long a, long long b) { if (a==0 || b==0) return 0LL; if (a<0) a=-a; if (b<0) b=-b; if (a>=INF || b>=INF) return INF; return safe_mul(a/gcd(a,b),b); }
template<class Res=long long> vector<Res> mkiota(int n, Res val=0) { vector<Res> res(n); iota(begin(res),end(res),val); return res; }
template<class T> T mkrev(const T &v) { T res=v; reverse(res.begin(),res.end()); return res; }
template<class T> vector<T> mksum(const vector<T> &v) { int s=v.size(); vector<T> res(s+1); for (int i=0;i<s;++i) res[i+1]=res[i]+v[i]; return res; }
template<class T> vector<T> mkdif(const vector<T> &v) { int s=v.size(); vector<T> res(s-1); for (int i=0;i+1<s;++i) res[i]=v[i+1]-v[i]; return res; }
template<class T> vector<T> mkuni(const vector<T> &v) { auto res=v; sort(res.begin(),res.end()); res.erase(unique(res.begin(),res.end()),res.end()); return res; }
template<class Res=long long,class T> vector<Res> mkinv(const vector<T> &v) { vector<Res> res(*max_element(v.begin(),v.end())+1,-1); for (int i=0,s=v.size();i<s;++i) res[v[i]]=i; return res; }
template<class Res=long long,class F> vector<Res> mkord(int n, F f) { vector<Res> res(n); iota(res.begin(),res.end(),0); stable_sort(res.begin(),res.end(),f); return res; }
template<class T> map<T,long long> mkcnt(const vector<T> &v) { map<T,long long> res; for (const auto &x : v) res[x]++; return res; }
template<class T,class F> vector<vector<T>> mksplit(const vector<T> &v, F f) { if (v.size()==0) return {}; vector<vector<T>> res{{v[0]}}; for (int i=0,s=v.size();i+1<s;++i) { if (f(v[i],v[i+1])) res.push_back({}); res.back().push_back(v[i+1]); } return res; }
template<class T> vector<pair<T,long long>> mkrle(const vector<T> &v) { int n=v.size(); vector<pair<T,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && v[i]==v[i+1]) { cnt++; i++; } res.emplace_back(v[i],cnt); } return res; }
vector<pair<char,long long>> mkrle(const string &s) { int n=s.size(); vector<pair<char,long long>> res; for (int i=0;i<n;++i) { long long cnt=1; while (i+1<n && s[i]==s[i+1]) { cnt++; i++; } res.emplace_back(s[i],cnt); } return res; }
template<class T> atcoder::fenwick_tree<T> mkfen(const vector<T> &v) { int s=v.size(); atcoder::fenwick_tree<T> res(s); for (int i=0;i<s;++i) res.add(i,v[i]); return res; }
template<class T> T min(const vector<T> &v) { return *min_element(v.begin(),v.end()); }
template<class T> T max(const vector<T> &v) { return *max_element(v.begin(),v.end()); }
template<class T> inline void sort(T &v, bool rev=false) { rev ? sort(v.rbegin(),v.rend()) : sort(v.begin(),v.end()); }
template<class T,class U> long long count(const T &v, const U &item) { return count(v.begin(),v.end(),item); }
template<class T> inline long long count_in_range(const vector<T> &v, const T &l, const T &r) { return lower_bound(v.begin(),v.end(),r)-lower_bound(v.begin(),v.end(),l); }
template<class T> inline long long lob(const vector<T> &v, const T &x) { return lower_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> inline long long upb(const vector<T> &v, const T &x) { return upper_bound(v.begin(),v.end(),x)-v.begin(); }
template<class T> optional<long long> minel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]<v[b]; })[k]; }
template<class T> optional<long long> maxel(const vector<T> &v, size_t k=0) { if (v.size()<=k) return nullopt; return mkord(v.size(),[&](long long a, long long b)->bool { return v[a]>v[b]; })[k]; }
template<class T> T flatten(const vector<T> &vv) { T res; for (const T &v : vv) res.insert(res.end(),v.begin(),v.end()); return res; }
vector<long long> binary_split(long long x) { assert(x>=0); vector<long long> res; long long k=1; while (x>0) { long long y=min(k,x); res.push_back(y); x-=y; k<<=1; } return res; }
template<class T> T arithmetic_series(T a, T d, T n) { return (a*2+(n-1)*d)*n/2; }
template<class T> long long hamming_distance(const T &a, const T &b) { assert(a.size()==b.size()); auto ita=a.begin(); auto itb=b.begin(); int res=0; while (ita!=a.end()) if (*ita++!=*itb++) res++; return res; }
template<class T> long long get_period(const T &v) { int n=v.size(); vector<int> z=atcoder::z_algorithm(v); for (int i=1;i<=n/2;++i) if (n%i==0 && z[i]==n-i) return i; return n; }
template<class T> void cumulative_min(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=min(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=min(v[i],v[i+1]); }
template<class T> void cumulative_max(vector<T> &v, bool ltr) { int n=v.size(); if (ltr) for (int i=0;i+1<n;++i) v[i+1]=max(v[i+1],v[i]); else for (int i=n-2;i>=0;--i) v[i]=max(v[i],v[i+1]); }
template<class T> void repeat_vector(vector<T> &v, int count=2) { assert(count>=0); if (count==0) { v.clear(); return; } count--; int original_size=v.size(); while (count--) v.insert(v.end(),v.begin(),v.begin()+original_size); }
template<class T> long long longest_continuum(const vector<T> &v) { if (v.empty()) return 0; long long res=1; long long now=1; int n=v.size(); for (int i=1;i<n;++i) if (v[i]==v[i-1]) chmax(res,++now); else now=1; return res; }
template<class T> long long longest_continuum(const vector<T> &v, const T &item) { long long res=0; long long now=0; for (auto &x : v) if (x==item) chmax(res,++now); else now=0; return res; }
template<class T> long long lis_len(const vector<T> &v, bool strict=true) { vector<T> dp; for (auto &x : v) { auto it=strict ? lower_bound(dp.begin(),dp.end(),x) : upper_bound(dp.begin(),dp.end(),x); if (it==dp.end()) dp.push_back(x); else *it=x; } return dp.size(); }
template<class T> long long inversions(vector<T> &v) { map<T,int> cc; for (auto &x : v) cc[x]=0; int M=0; for (auto &[key,val] : cc) val=M++; long long res=0; atcoder::fenwick_tree<long long> fen(M); for (auto &x : v) { int y=cc[x]; res+=fen.sum(y+1,M); fen.add(y,1); } return res; }
long long ctok(char d) { switch (d) { case 'D': return 0; case 'R': return 1; case 'U': return 2; case 'L': return 3; } return -1; }
template<class T> T min_op(T a, T b) { return min(a,b); }
template<class T> T max_op(T a, T b) { return max(a,b); }
template<class T> using min_segtree=atcoder::segtree<T,min_op<T>,numeric_limits<T>::max>;
template<class T> using max_segtree=atcoder::segtree<T,max_op<T>,numeric_limits<T>::lowest>;
template<class U> class FenwickTree {
private:
int _n;
std::vector<U> data;
U sum(int r) const {
U s=U(0);
while (r>0) {
s+=data[r-1];
r-=r&-r;
}
return s;
}
int max_right(U x, bool eq) const {
if (_n==0) return 0;
int d=1<<(31-__builtin_clz(_n));
int i=0;
U now=0;
while (d) {
int j=i+d-1;
if (j<_n && (eq ? now+data[j]<=x : now+data[j]<x)) {
now+=data[j];
i+=d;
}
d>>=1;
}
return i;
};
public:
FenwickTree() : _n(0) {}
FenwickTree(int n) : _n(n), data(n) {}
FenwickTree(const std::initializer_list<U> &init) : _n(init.size()), data(init.size()) {
auto it=init.begin();
int i=0;
while (it!=init.end()) add(i++,*it++);
}
FenwickTree(const std::vector<U> &v) : _n(v.size()), data(v.size()) {
for (int i=0;i<_n;++i) add(i,v[i]);
}
void add(int p, U x) {
assert(0<=p && p<_n);
p++;
while (p<=_n) {
data[p-1]+=x;
p+=p&-p;
}
}
void set(int p, U x) {
add(p,x-sum(p,p+1));
}
U sum(int l, int r) const {
assert(0<=l && l<=r && r<=_n);
return sum(r)-sum(l);
}
int max_right(int l, U x, bool eq) const {
assert(0<=l && l<=_n);
if (l==0) return max_right(x,eq);
return max_right(sum(l)+x,eq);
}
int min_left(int r, U x, bool eq) const {
assert(0<=r && r<=_n);
U sum_r=sum(r);
if (eq ? sum_r<=x : sum_r<x) return 0;
return max_right(sum_r-x,!eq)+1;
}
void clear() {
data.assign(_n,U(0));
}
friend std::ostream &operator<<(std::ostream &os, const FenwickTree &fen) {
U prev=0;
for (int i=1;i<=fen._n;++i) {
U next=fen.sum(i);
os<<next-prev;
prev=next;
if (i!=fen._n) os<<' ';
}
return os;
}
};
template<class T, bool ALLOWS_NEGATIVE=true> class PrioritySum {
private:
using C=long long;
C _all_cnt=0;
T _all_sum=0;
FenwickTree<C> cnt_fen;
FenwickTree<T> sum_fen;
std::vector<T> cc;
bool initialized=false;
void check_cc() const {
for (auto x : cc) assert(x>=T(0));
}
public:
PrioritySum() {}
PrioritySum(const std::initializer_list<T> &init) : cc(init) { if (!ALLOWS_NEGATIVE) check_cc(); }
PrioritySum(const std::vector<T> &v) : cc(v) { if (!ALLOWS_NEGATIVE) check_cc(); }
void prepare(T x) {
assert(!initialized);
assert(ALLOWS_NEGATIVE || x>=T(0));
cc.push_back(x);
}
void prepare(const std::vector<T> &v) {
for (auto x : v) prepare(x);
}
void init() {
std::sort(cc.begin(),cc.end());
cc.erase(std::unique(cc.begin(),cc.end()),cc.end());
cnt_fen=FenwickTree<C>(cc.size());
sum_fen=FenwickTree<T>(cc.size());
initialized=true;
}
void add(T x, C count=1) {
assert(initialized);
unsigned int idx=std::lower_bound(cc.begin(),cc.end(),x)-cc.begin();
assert(idx<cc.size() && cc[idx]==x);
x*=count;
cnt_fen.add(idx,count);
sum_fen.add(idx,x);
_all_cnt+=count;
_all_sum+=x;
}
void erase(T x, C count=1) {
add(x,-count);
}
T operator[](C k) const {
assert(initialized);
k%=_all_cnt;
if (k<C(0)) k+=_all_cnt;
return cc[cnt_fen.max_right(0,k,true)];
}
T kth_smallest(C k) const {
assert(0<=k && k<_all_cnt);
return (*this)[k];
}
T kth_largest(C k) const {
assert(0<=k && k<_all_cnt);
return (*this)[-1-k];
}
T pop_min() {
T res=kth_smallest(0);
erase(res);
return res;
}
T pop_max() {
T res=kth_largest(0);
erase(res);
return res;
}
std::vector<T> medians() const {
assert(initialized);
if (_all_cnt==0) return {};
if (_all_cnt%2==1) return {(*this)[_all_cnt/2]};
return {(*this)[_all_cnt/2-1],(*this)[_all_cnt/2]};
}
T smallest_sum(C count) const {
assert(initialized);
if (_all_cnt<=count) return _all_sum;
int k=cnt_fen.max_right(0,count,true);
return sum_fen.sum(0,k)+cc[k]*(count-cnt_fen.sum(0,k));
}
T largest_sum(C count) const {
assert(initialized);
if (_all_cnt<=count) return _all_sum;
return _all_sum-smallest_sum(_all_cnt-count);
}
T all_sum() const {
assert(initialized);
return _all_sum;
}
C size() const {
assert(initialized);
return _all_cnt;
}
void clear() {
assert(initialized);
cnt_fen.clear();
sum_fen.clear();
_all_cnt=0;
_all_sum=0;
}
C count_lt(T x) const {
return cnt_fen.sum(0,std::lower_bound(cc.begin(),cc.end(),x)-cc.begin());
}
C count_leq(T x) const {
return cnt_fen.sum(0,std::upper_bound(cc.begin(),cc.end(),x)-cc.begin());
}
C count_gt(T x) const {
return _all_cnt-count_leq(x);
}
C count_geq(T x) const {
return _all_cnt-count_lt(x);
}
std::optional<T> nearest_geq(T x) const {
unsigned int idx=std::lower_bound(cc.begin(),cc.end(),x)-cc.begin();
unsigned int k=cnt_fen.max_right(idx,1,false);
if (k==cc.size()) return std::nullopt;
return cc[k];
}
std::optional<T> nearest_gt(T x) const {
unsigned int idx=std::upper_bound(cc.begin(),cc.end(),x)-cc.begin();
unsigned int k=cnt_fen.max_right(idx,1,false);
if (k==cc.size()) return std::nullopt;
return cc[k];
}
std::optional<T> nearest_leq(T x) const {
unsigned int idx=std::upper_bound(cc.begin(),cc.end(),x)-cc.begin();
unsigned int k=cnt_fen.min_left(idx,1,false);
if (k==0) return std::nullopt;
return cc[k-1];
}
std::optional<T> nearest_lt(T x) const {
unsigned int idx=std::lower_bound(cc.begin(),cc.end(),x)-cc.begin();
unsigned int k=cnt_fen.min_left(idx,1,false);
if (k==0) return std::nullopt;
return cc[k-1];
}
std::vector<T> nearest_both(T x) const {
std::optional<T> lt=nearest_lt(x);
std::optional<T> geq=nearest_geq(x);
T dist=std::numeric_limits<T>::max();
if (lt!=std::nullopt && x-lt.value()<dist) dist=x-lt.value();
if (geq!=std::nullopt && geq.value()-x<dist) dist=geq.value()-x;
std::vector<T> res;
if (lt!=std::nullopt && x-lt.value()==dist) res.push_back(lt.value());
if (geq!=std::nullopt && geq.value()-x==dist) res.push_back(geq.value());
return res;
}
C max_count_leq_volume(T volume) const requires(!ALLOWS_NEGATIVE) {
assert(T(0)<=volume);
if (volume>=_all_sum) return _all_cnt;
int k=sum_fen.max_right(0,volume,true);
return cnt_fen.sum(0,k)+C((volume-sum_fen.sum(0,k))/cc[k]);
};
C min_count_geq_volume(T volume) const requires(!ALLOWS_NEGATIVE) {
assert(T(0)<=volume && volume<=_all_sum);
return _all_cnt-max_count_leq_volume(_all_sum-volume);
}
friend std::ostream &operator<<(std::ostream &os, const PrioritySum &v) {
bool spacing=false;
for (unsigned int i=0;i<v.cc.size();++i) {
int c=v.cnt_fen.sum(i,i+1);
if (c==0) continue;
if (spacing) os<<' '; else spacing=true;
os<<v.cc[i]<<'*'<<c;
}
return os;
}
};
int main() {
ll N,B;
cin>>N>>B;
vector<ll> C(N),S(N);
cin>>C>>S;
PrioritySum<ll,false> ps(C);
ps.prepare(1);
ps.init();
for (ll i=0;i<N;++i) ps.add(C[i],S[i]);
ll ans=ps.max_count_leq_volume(B);
for (ll i=0;i<N;++i) {
ps.erase(C[i],S[i]);
ps.add(1,S[i]);
chmax(ans,ps.max_count_leq_volume(B));
ps.erase(1,S[i]);
ps.add(C[i],S[i]);
}
cout<<ans<<'\n';
}