QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#758256#9599. Dragon BloodlineMaxduan#WA 311ms7000kbC++201.1kb2024-11-17 17:12:252024-11-17 17:12:26

Judging History

你现在查看的是最新测评结果

  • [2024-11-17 17:12:26]
  • 评测
  • 测评结果:WA
  • 用时:311ms
  • 内存:7000kb
  • [2024-11-17 17:12:25]
  • 提交

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=1e18;
    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: 1ms
memory: 3788kb

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: 0
Accepted
time: 0ms
memory: 3572kb

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:

1048575000000000

result:

ok single line: '1048575000000000'

Test #3:

score: 0
Accepted
time: 0ms
memory: 3728kb

input:

2
3 2
1 1 1
1 7
4 2
1 1 1 1
1 2

output:

4
0

result:

ok 2 lines

Test #4:

score: 0
Accepted
time: 311ms
memory: 7000kb

input:

1
50000 20
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...

output:

1048575

result:

ok single line: '1048575'

Test #5:

score: -100
Wrong Answer
time: 53ms
memory: 3524kb

input:

1000
37 20
2 8 8 7 8 7 4 6 7 4 7 4 8 4 4 5 8 3 5 5 7 7 10 6 3 2 5 3 5 8 3 6 2 4 7 3 3
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
9 12
4 7 12 6 12 18 11 35 19
3 8 2 6 3 6 4 3 8 4 4 9
26 13
9 9 5 3 4 5 2 10 4 6 6 9 5 3 9 10 6 2 10 4 2 9 9 3 9 3
1 1 1 1 1 1 1 1 1 1 1 1 1
33 18
3 5 3 3 4 1 4 3 1 4 5 1 3 4 ...

output:

0
222
0
18103
0
0
0
12
797285632470705503
90
697728952654285535
77
4
0
78
4
5
18
571220200009756000
636094623231363859
152163350649677937
47
0
530853929099644449
2307
85
0
305565332515576748
352
16
33274765353562094
39
1
21
231738856064260042
212009587096889649
0
0
5631
619922726030567174
5517344537...

result:

wrong answer 9th lines differ - expected: '0', found: '797285632470705503'