This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "robots.h"
using namespace std;
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
cerr<<vars<<" = ";
string delim="";
(...,(cerr<<delim<<values,delim=", "));
cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mxN=5e4+5; //make sure this is right
const int mod=1e9+7;
int tot[mxN];
vector<int> x,y;
vector<pii> toys;
bool check(int k){
int active=0; int cnt=0;
set<pii> av;
priority_queue<int> q;
priority_queue<int,vector<int>,greater<int>> q2;
for(int i=0;i<sz(x);i++)
q.push(x[i]);
for(int i=0;i<sz(y);i++){
av.insert({y[i],i});
tot[i]=0;
}
for(auto &u:toys){
while(sz(q) && q.top()>u.first){
active++; q.pop();
}
q2.push(u.second);
cnt++;
if(active==0 || (cnt+active-1)/active>k){
cnt--;
assert(sz(q2));
int take=q2.top(); q2.pop();
if(av.empty())
return 0;
if(take>=av.rbegin()->first)
return 0;
pii go=*av.upper_bound(pii(take,1e9));
tot[go.second]++;
if(tot[go.second]==k)
av.erase(go);
}
}
return 1;
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
int ans=-1;
for(int i=0;i<A;i++)
x.pb(X[i]);
for(int i=0;i<B;i++)
y.pb(Y[i]);
for(int i=0;i<T;i++)
toys.pb({W[i],S[i]});
sort(x.begin(),x.end());
sort(toys.rbegin(),toys.rend());
int l=1; int r=T;
while(l<=r){
int mid=(l+r)>>1;
if(check(mid)){
ans=mid; r=mid-1;
} else{
l=mid+1;
}
}
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |