QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#721344 | #9599. Dragon Bloodline | rotcar07 | RE | 0ms | 3556kb | C++23 | 831b | 2024-11-07 15:54:03 | 2024-11-07 15:54:03 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,k,a[50005],b[25];
typedef long long ll;
ll t[50005];
inline bool chk(ll d){
for(int i=1;i<=n;i++) t[i]=a[i]*d;
for(int i=k;i>=1;i--){
ll cur=b[i];
for(int j=1;j<=n;j++){
ll w=(t[j]>>i-1);
if(w>=cur){
t[j]-=cur<<i-1;
cur=0;
break;
}
else t[j]&=(1<<i-1)-1,cur-=w;
}
if(cur){
nth_element(t+1,t+cur,t+n+1,greater<ll>());
for(int i=1;i<=cur;i++) t[i]=0;
}
}
for(int i=1;i<=n;i++) if(t[i]) return 0;
return 1;
}
inline void solve(){
cin>>n>>k;
int mx=0;
for(int i=1;i<=n;i++) cin>>a[i],mx=max(mx,a[i]);
for(int i=1;i<=k;i++) cin>>b[i];
ll l=0,r=3e15/mx;
while(l<r){
ll mid=l+r+1>>1;
if(chk(mid)) l=mid;
else r=mid-1;
}
cout<<l<<'\n';
}
int main(){
int t;cin>>t;
while(t--) solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3556kb
input:
6 4 3 1 2 3 4 4 4 4 3 2 1 1 1 1 7 3 4 6 6 2 1 1 5 5 3 5 3 1 1 1 1 1 1 1 4 5 1 9 9 8 2 2 2 3 1 5 4 1 3 1 7 1 4 1 5 2
output:
2 4 4 5 2 3
result:
ok 6 lines
Test #2:
score: -100
Runtime Error
input:
1 1 20 1 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000