QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#723683 | #9600. Eat, Sleep, Repeat | LightFeather | TL | 0ms | 0kb | C++20 | 1.7kb | 2024-11-07 23:39:15 | 2024-11-07 23:39:15 |
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define ld long double
#define lll __int128
#define dhm std::fixed<<std::setprecision
#define prq priority_queue
using ll = long long;
using ull = unsigned long long;
typedef pair<int, int> PII;
int T;
template <typename T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <typename T>
using max_heap = priority_queue<T, vector<T>, less<T>>;
int sum[30];
void solve(){
int n,k;
std::cin>>n>>k;
std::vector<ll>a(n+1);
for(int i = 1; i <= n ; i ++) {
std::cin>>a[i];
}
std::vector<ll>b(60+1);
std::vector<ll>bb(60+1);
for(int i = 1; i <= k ; i ++) {
std::cin>>b[i];
}
ll l = 0;
ll r = 1e18;
auto check = [&](ll x)->bool {
bb = b;
max_heap<int> q;
for(int i=1;i<=n;i++) {
q.push(a[i]*x*1ll);
}
int f=k-1;
while(!q.empty()) {
if(f<0) return 0;
int t=q.top();
q.pop();
int cnt=max(1ll,min(bb[f+1],t/sum[f]));
t=t-cnt*sum[f];
if(t>0) q.push(t);
bb[f+1]-=cnt;
if(bb[f+1]==0) {
f--;
}
}
return 1;
};
while(l<r) {
ll mid = l + r+1>>1;
if(check(mid)) l = mid;
else r = mid - 1;
}
std::cout<<l<<endl;
}
signed main(){
std::ios::sync_with_stdio(false);
std::cin.tie(0);
sum[0]=1;
sum[1]=2;
for(int i=2;i<=29;i++) {
sum[i]=sum[i-1]*2;
}
T = 1;
std::cin>>T;
while(T --)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Time Limit Exceeded
input:
5 2 0 1 2 2 1 1 2 0 1 3 2 3 3 4 0 2 1 1 3 2 2 3 3 1 2 0 1 5 4 6 7 8 12 17 1 1 2 1 9 0 10 1