QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#758087 | #9599. Dragon Bloodline | Maxduan# | WA | 0ms | 3828kb | C++20 | 1.1kb | 2024-11-17 15:44:19 | 2024-11-17 15:44:19 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define maxn 200005
#define int long long
#define i128 __int128
int a[maxn],b[maxn];
int n,m;
bool check(int k){
priority_queue<i128>pq;
for(int i=1;i<=n;i++){
pq.push((i128)a[i]*k);
}
for(int i=m-1;i>=0;i--){
i128 cnt=b[i];
i128 tmp=(1<<i);
while(pq.size()&&pq.top()>=tmp&&cnt>0){
int now=pq.top();
pq.pop();
i128 mm=min(now/tmp,cnt);
now-=mm*tmp;
cnt-=mm;
if(now>0)pq.push(now);
}
while(pq.size()&&cnt--){
pq.pop();
}
}
return pq.empty();
}
void solve(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=0;i<m;i++){
cin>>b[i];
}
int l=1,r=1e11;
while(l<=r){
int mid=l+r>>1;
if(check(mid)){
l=mid+1;
}
else{
r=mid-1;
}
}
cout<<l-1<<'\n';
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
int TT=1;cin>>TT;
while(TT--){
solve();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3828kb
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
Wrong Answer
time: 0ms
memory: 3612kb
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
output:
100000000000
result:
wrong answer 1st lines differ - expected: '1048575000000000', found: '100000000000'