Maximum Product
#include
using namespace std;
typedef long long ll;
vector a,b,ans;
ll n;
ll product(const vector &v)
{
ll ret=1,i=0;
while(!v[i])++i;
for(; i v(b);
--v[i];
fill(v.begin()+i+1,v.end(),9);
if(v>=a&&product(ans)
Biathlon 2.0
#include
#include
#include
using namespace std;
const int maxn=500000+10;
typedef long long ll;
struct track
{
ll a,b,id;
}t[maxn];
struct rifle
{
ll c,d;
}q[maxn],r[maxn];
ll n,m,cur,cnt;
ll ans[maxn];
bool cmp0(rifle x,rifle y)
{
if (x.c!=y.c) return x.c(y.a*x.b);}
int main()
{
scanf("%lld",&n);
for (int i=1;i<=n;i++) scanf("%lld%lld",&t[i].a,&t[i].b),t[i].id=i;
scanf("%lld",&m);
for (int i=1;i<=m;i++) scanf("%lld%lld",&q[i].c,&q[i].d);
sort(t+1,t+n+1,cmp1);
// for (int i=1;i<=n;i++) printf("%lld %lld %lld\n",t[i].a,t[i].b,t[i].id);
sort(q+1,q+m+1,cmp0);
r[1]=q[1]; cnt=1;
for (int i=2;i<=m;i++)
{
if (q[i].c==r[cnt].c) continue;
if (q[i].d>=r[cnt].d) continue;
r[++cnt]=q[i];
}
// for (int i=1;i<=cnt;i++) printf("%d %d\n",r[i].c,r[i].d);
memset(q,0,sizeof(q));
q[1]=r[1];
q[2]=r[2];
int l=2;
for (int i=3;i<=cnt;i++)
{
while ((l>1)&&((q[l].d-q[l-1].d)*(q[l].c-r[i].c)<(q[l-1].c-q[l].c)*(r[i].d-q[l].d))) l--;
q[++l]=r[i];
}
cur=1;
if (cnt==1) l=1;
for (int i=1;i<=n;i++)
{
while ((cur(t[i].a*q[cur+1].c+t[i].b*q[cur+1].d))) cur++;
ans[t[i].id]=t[i].a*q[cur].c+t[i].b*q[cur].d;
}
for (int i=1;i<=n;i++) printf("%lld ",ans[i]);
return 0;
}
Sockets
#include
using namespace std;
typedef long long ll;
const ll N=2e5+9;
ll n,m,a[N],b[N],c[N],s[N];
int main()
{
scanf("%lld%lld",&n,&m);
for(ll i=0; i