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;
//#define int ll
#define FOR(i,s,e) for(ll i = s; i <= (ll)e; ++i)
#define DEC(i,s,e) for(ll i = s; i >= (ll)e; --i)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
#define db(x) cerr << #x << "=" << x << "\n"
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << "\n"
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<"\n"
#define dbv(v) cerr << #v << ":"; for (auto ite : v) cerr << ite << ' '; cerr <<"\n"
#define dbvp(v) cerr << #v << ":"; for (auto ite : v) cerr << "{" << ite.f << ',' << ite.s << "} "; cerr << "\n"
#define dba(a,ss,ee) cerr << #a << ":"; FOR(ite,ss,ee) cerr << a[ite] << ' '; cerr << "\n"
#define reach cerr << "LINE: " << __LINE__ << "\n";
#else
#define db(x)
#define db2(x,y)
#define db3(a,b,c)
#define dbv(v)
#define dbvp(v)
#define dba(a,ss,ee)
#define reach
#endif
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define g0(x) get<0>(x)
#define g1(x) get<1>(x)
#define g2(x) get<2>(x)
#define g3(x) get<3>(x)
typedef pair <ll, ll> pi;
typedef tuple<ll,ll,ll> ti3;
typedef tuple<ll,ll,ll,ll> ti4;
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
const int inf = (int)1e9 + 500;
const long long oo = (ll)1e18 + 500;
template <typename T> bool chmax(T& a, const T b) { return a<b ? a = b, 1 : 0; }
template <typename T> bool chmin(T& a, const T b) { return a>b ? a = b, 1 : 0; }
const int MAXN = 1000005;
const int MAXM = 50005;
ll n,x,y;
pi A[MAXN];
ll Xx[MAXM], Yy[MAXM];
bool check(ll ti) {
priority_queue<ll,vector<ll>,greater<ll>> pot;
multiset<pi> small;
FOR(i,1,y)small.insert(pi(Yy[i],ti));
int weaks=0;
int weakidx=x;
FOR(i,1,n) {
while(weakidx&&Xx[weakidx]>A[i].f) {
weaks+=ti;
weakidx--;
}
if(weaks) {
weaks--;
pot.push(A[i].s);
continue;
}
pot.push(A[i].s);
ll best=pot.top();
if(small.empty())return 0;
auto it=small.lower_bound(pi(best,inf));
if(it==small.end())return 0;
auto p = *it;
p.s--;
small.erase(it);
if(p.s)small.insert(p);
pot.pop();
}
return 1;
}
int putaway(int _A, int _B, int _T, int _X[], int _Y[], int _W[], int _S[]) {
x=_A,y=_B,n=_T;
FOR(i,1,n) {
A[i] = pi(_W[i-1], _S[i-1]);
}
FOR(i,1,x) {
Xx[i]=_X[i-1];
}
FOR(i,1,y) {
Yy[i]=_Y[i-1];
}
sort(Xx+1,Xx+x+1);
sort(Yy+1,Yy+y+1);
sort(A+1,A+n+1,[](pi a, pi b) {
if(a.f==b.f)return a.s < b.s;
else return a.f > b.f;
});
int lo = 0, hi = n+1;
if(!check(hi))return -1;
while(lo<hi-1) {
ll mid=(lo+hi)/2;
if(check(mid))hi=mid;
else lo=mid;
}
return hi;
}
#ifdef LOCAL
#define fail(s, x...) do { \
fprintf(stderr, s "\n", ## x); \
exit(1); \
} while(0)
#define MAX_A 50000
#define MAX_B 50000
#define MAX_T 500000
static int X[MAX_A];
static int Y[MAX_B];
static int W[MAX_T];
static int S[MAX_T];
int main() {
int A, B, T, i;
int res;
//FILE *f = fopen("robots.in", "r");
//if (!f)
// fail("Failed to open input file.");
res = scanf("%d", &A);
if (res != 1)
fail("Failed to read A from input file.");
if (A < 0 || A > MAX_A)
fail("A is out of bounds.");
res = scanf( "%d", &B);
if (res != 1)
fail("Failed to read B from input file.");
if (B < 0 || B > MAX_B)
fail("B is out of bounds.");
res = scanf("%d", &T);
if (res != 1)
fail("Failed to read T from input file.");
if (T < 1 || T > MAX_T)
fail("T is out of bounds.");
for (i = 0; i < A; i++) {
res = scanf( "%d", &X[i]);
if (res != 1)
fail("Failed to read data from input file.");
}
for (i = 0; i < B; i++) {
res = scanf( "%d", &Y[i]);
if (res != 1)
fail("Failed to read data from input file.");
}
for (i = 0; i < T; i++) {
res = scanf("%d%d", &W[i], &S[i]);
if (res != 2)
fail("Failed to read data from input file.");
}
//fclose(f);
int answer = putaway(A, B, T, X, Y, W, S);
printf("%d\n", answer);
return 0;
}
#endif
# | 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... |