QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205608 | #6632. Minimize Median | Geospiza# | WA | 0ms | 7860kb | C++14 | 1.9kb | 2023-10-07 16:45:14 | 2023-10-07 16:45:14 |
Judging History
answer
#include <bits/stdc++.h>
#define ll long long
#define Ma 1000005
#define mod 998244353
#define N 1005
#define pb push_back
#define ls p<<1
#define rs p<<1|1
using namespace std;
ll inf=1e18;
ll a[Ma],c[Ma];
ll n,m,k;
bool ask(ll x)
{
ll cnt=0;
for (ll i=1;i<=(n+1)/2;i++)
{
cnt+=c[a[i]/(x+1)+1];
}
printf("x=%lld cnt=%lld\n",x,cnt);
return (cnt<=k);
}
struct sgtree{
ll l,r,w;
}t[Ma<<2];
void build(ll p,ll l,ll r)
{
t[p].l=l,t[p].r=r,t[p].w=inf;
if (l==r)
{
t[p].w=c[l];
return ;
}
ll mid=(l+r)>>1;
build(ls,l,mid);
build(rs,mid+1,r);
t[p].w=min(t[ls].w,t[rs].w);
return;
}
void change(ll p,ll l,ll r,ll d){
if (l<=t[p].l&&t[p].r<=r){
t[p].w=min(t[p].w,d);
return;
}
ll mid=(t[p].l+t[p].r)>>1;
if (l<=mid) change(ls,l,r,d);
if (r>mid) change(rs,l,r,d);
t[p].w=min(t[ls].w,t[rs].w);
return;
}
ll ask(ll p,ll l,ll r)
{
if (l<=t[p].l&&t[p].r<=r) return t[p].w;
ll val=inf;
ll mid=(t[p].l+t[p].r)>>1;
if (l<=mid) val=min(val,ask(ls,l,r));
if (r>mid) val=min(val,ask(rs,l,r));
return val;
}
void sol()
{
cin>>n>>m>>k;
for (ll i=1;i<=n;i++)
cin>>a[i];
sort(a+1,a+n+1);
for (ll i=1;i<=m;i++)
cin>>c[i];
c[1]=0;
c[m+1]=inf;
build(1,1,m+1);
for (ll i=1;i<=m+1;i++)
{
c[i]=ask(1,i,m+1);
for (ll j=i*2;j<=m+i;j+=i)
{
ll id=min(j,m+1);
change(1,id,id,c[i]+c[j/i]);
}
}
ll l=0,r=m;
while (l<=r)
{
ll mid=(l+r)>>1;
if (ask(mid))
r=mid-1;
else
l=mid+1;
}
printf("%lld\n",l);
}
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
ll tt=1;
cin>>tt;
while (tt--)
sol();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 7860kb
input:
3 3 5 0 2 5 2 3 2 4 6 13 3 5 3 2 5 3 3 2 4 6 13 3 5 6 2 5 2 3 2 4 6 13
output:
x=2 cnt=0 x=0 cnt=8 x=1 cnt=4 2 x=2 cnt=2 x=0 cnt=8 x=1 cnt=4 2 x=2 cnt=0 x=0 cnt=8 x=1 cnt=4 1
result:
wrong output format Expected integer, but "x=2" found