#include "robots.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
//mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
//ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;
vector<pii> events;
vector<pii> events2;
pii toy[1000'001];
bool was[1000'001];
int A,B,T;
bool check(ll w)
{
priority_queue<pii,vector<pii>,greater<pii>> best;
ll cur = 0;
rep2(i,1,T) was[i] = 0;
forall(it,events)
{
if(it.ss >= 0)
{
cur += w;
}
else
{
best.push({toy[-it.ss].ss,-it.ss});
cur--;
if(cur == -1)
{
cur = 0;
pii t = best.top();
best.pop();
was[t.ss] = 1;
}
}
// cout << it.ff << " " << it.ss << " " << cur << " cur\n";
}
cur = 0;
forall(it,events2)
{
if(it.ss >= 0)
{
cur += w;
}
else
{
if(!was[-it.ss]) continue;
if(cur == 0) return 0;
cur--;
}
}
return 1;
}
int putaway(int a, int b, int t, int X[], int Y[], int W[], int S[])
{
A = a;
B = b;
T = t;
rep2(i,1,T)
{
toy[i] = {W[i-1],S[i-1]};
events.pb({W[i-1],-i});
events2.pb({S[i-1],-i});
}
rep(i,A)
{
events.pb({X[i]-1,i});
}
rep(i,B)
{
events2.pb({Y[i]-1,i});
}
sort(all(events));
reverse(all(events));
sort(all(events2));
reverse(all(events2));
int ans = -1;
int l = 1;
int r = 1;
while(l <= r)
{
int mid = (l+r)/2;
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... |