NOIP 模拟 $85\; \rm 尽梨了$
题解 \(by\;zj\varphi\)
每次多选一个商场,所用时间在 \(a_i\) 不为 \(0\) 的情况下至少乘二。
所以答案不会很大,\(dp\) 数组只需开 \(log_2n\) 即可。
退一下式子,假设在当前已经过去了 \(t\) 时间,该前往下一个商场了,那么有:
\[a_j\times (a_i\times (t+1)+b_i+(t+1)+1)+b_j+a_i\times (t+1)+b_i+(t+1)+1\le a_i\times (a_j\times (t+1)+b_j+(t+1)+1)+b_i+a_j\times (t+1)+b_j+(t+1)+1
\]
解得 \(\frac{b_i+1}{a_i}\le \frac{b_j+1}{a_j}\)。
那么先按 \(\frac{b_i+1}{a_i}\le \frac{b_j+1}{a_j}\) 从下到大排序,然后再 \(dp\),方程为 \(f_{i,j}=\min(f_{i,j},f_{i-1,j-1}+time_i)\)。
\(time_i\) 表示第 \(i\) 个商场所用的时间。
剩下的 \(a_i\) 为 \(0\) 的放到最后枚举添加进答案。
Code
#include<bits/stdc++.h>
#define ri signed
#define pd(i) ++i
#define bq(i) --i
#define func(x) std::function<x>
namespace IO{
char buf[1<<21],*p1=buf,*p2=buf;
#define gc() p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?(-1):*p1++
#define debug1(x) std::cerr << #x"=" << x << ' '
#define debug2(x) std::cerr << #x"=" << x << std::endl
#define Debug(x) assert(x)
struct nanfeng_stream{
template<typename T>inline nanfeng_stream &operator>>(T &x) {
bool f=false;x=0;char ch=gc();
while(!isdigit(ch)) f|=ch=='-',ch=gc();
while(isdigit(ch)) x=(x<<1)+(x<<3)+(ch^48),ch=gc();
return x=f?-x:x,*this;
}
}cin;
}
using IO::cin;
namespace nanfeng{
#define FI FILE *IN
#define FO FILE *OUT
template<typename T>inline T cmax(T x,T y) {return x>y?x:y;}
template<typename T>inline T cmin(T x,T y) {return x>y?y:x;}
using ll=long long;
static const int N=2e5+7;
int f[50],n,T,ans,pos=1e9,sum;
struct Seg{int a,b;}s[N];
inline int main() {
FI=freopen("eriri.in","r",stdin);
FO=freopen("eriri.out","w",stdout);
cin >> n >> T;
for (ri i(1);i<=n;pd(i)) cin >> s[i].a >> s[i].b;
std::sort(s+1,s+n+1,[](const Seg &s1,const Seg &s2) {return 1ll*(s1.b+1)*s2.a<1ll*s1.a*(s2.b+1);});
memset(f,0x3f,sizeof(f));
f[0]=0;
for (ri i(1);i<=n;pd(i)) {
if (!s[i].a) {pos=i;break;}
for (ri j(cmin(29,i-1));~j;bq(j)) {
ll t=1ll*(s[i].a+1)*(f[j]+1)+s[i].b;
if (t>T) continue;
f[j+1]=cmin(f[j+1],(int)t);
}
}
for (ri i(cmin(pos-1,30));i;bq(i)) if (f[i]<=T) {ans=i;break;}
if (pos<=n) {
std::sort(s+pos,s+n+1,[](const Seg &s1,const Seg &s2) {return s1.b<s2.b;});
for (ri i(pos);i<=n;pd(i)) {
sum+=s[i].b+1;
if (sum>T) break;
for (ri j(cmin(pos-1,30));~j;bq(j))
if (sum+f[j]<=T) {ans=cmax(ans,j+i-pos+1);break;}
}
}
printf("%d\n",ans);
return 0;
}
}
int main() {return nanfeng::main();}