QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#721344#9599. Dragon Bloodlinerotcar07RE 0ms3556kbC++23831b2024-11-07 15:54:032024-11-07 15:54:03

Judging History

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

  • [2024-11-07 15:54:03]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3556kb
  • [2024-11-07 15:54:03]
  • 提交

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();
}

詳細信息

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

output:


result: