QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#147429 | #6632. Minimize Median | qzez# | WA | 75ms | 5960kb | C++14 | 1.5kb | 2023-08-23 08:58:26 | 2023-08-25 01:30:23 |
Judging History
answer
#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;using LL=__int128;
const int N=1e6+5,M=(1<<15)+5,K=14348907+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,m,k,A[N];ll w[N];
pair<int,ll> B[100];int Bh;
int CK(int mid){
ll tot=0;
for(int i=1;i<=(n+1)/2;i++){
if(mid==0) tot+=w[A[i]+1];
else tot+=w[(A[i]+mid-1)/mid];
}
// cerr<<mid<<' '<<tot<<'\n';
return tot<=k;
}
void Solve(){
int i,j,h;scanf("%d%d%d",&n,&m,&k);
for(i=1;i<=n;i++) scanf("%d",&A[i]);
for(i=1;i<=m;i++) scanf("%lld",&w[i]);w[1]=0;
sort(A+1,A+n+1);w[m+1]=INF;
ll Mi=INF;int R=m+1;
for(i=2;i<=m;i++){
if(1ll*i*i>m){
Mi=min(Mi,w[i]);
R=min(R,i);
while(1ll*R*i>m) Mi=min(Mi,w[i]),R--;
}
for(j=1;j<=R;j++) w[j*i]=min(w[j*i],w[j]+w[i]);
w[m+1]=min(w[m+1],Mi+w[i]);
}
for(i=m;i;i--) w[i]=min(w[i],w[i+1])/*,cerr<<w[i]<<' '*/;
int l=-1,r=m+1,mid;
while(l+1<r) mid=l+r>>1,(CK(mid)?r:l)=mid;
printf("%d\n",r);
}
int main(){
int t;
scanf("%d",&t);
// t=1;
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 5952kb
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:
2 2 1
result:
ok 3 number(s): "2 2 1"
Test #2:
score: -100
Wrong Answer
time: 75ms
memory: 5960kb
input:
100000 5 10 5 3 7 1 10 10 11 6 11 6 1 8 9 1 3 1 5 6 51 2 2 2 5 1 42 61 26 59 100 54 5 10 76 7 5 8 4 7 97 4 44 83 61 45 24 88 44 44 5 8 90 1 1 5 1 3 35 15 53 97 71 83 26 7 5 3 52 1 1 3 1 1 22 6 93 5 6 28 6 6 1 3 1 9 31 2 19 10 27 5 8 31 3 6 2 1 2 32 29 13 7 57 34 9 5 5 6 75 3 3 4 5 4 40 56 38 60 17 3...
output:
0 2 0 0 0 0 0 0 3 4 0 0 0 0 1 1 0 0 0 0 1 1 0 2 2 0 0 0 0 0 2 0 0 0 2 2 0 1 0 0 0 0 1 0 2 4 1 1 0 0 2 0 0 7 0 2 0 0 0 1 1 0 1 0 1 0 0 2 1 0 6 3 0 0 1 0 2 0 0 3 0 1 0 1 0 2 0 0 0 0 1 2 2 4 0 0 0 0 0 0 1 2 2 1 2 2 0 1 1 0 0 0 0 0 1 2 1 4 1 0 4 1 2 1 0 0 0 0 1 2 1 0 0 2 3 1 0 1 1 1 0 1 5 0 1 2 0 2 0 0 ...
result:
wrong answer 56th numbers differ - expected: '1', found: '2'