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"
#pragma GCC optimization ("O3")
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
const int N = int(1e6) + 1;
const int M = int(5e4) + 1;
typedef pair<int, int> pii;
vector<pii> BaeW, BaeS;
vector<bool> del;
priority_queue<pii> pq;
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{ // A -> W, B -> S
sort(X, X + A); sort(Y, Y + B);
for(int i = 0; i < T; ++i) BaeS.pb(S[i], i), BaeW.pb(W[i], i);
sort(BaeS.begin(), BaeS.end());
sort(BaeW.begin(), BaeW.end());
int low = 1, high = T, mid, j, cur, cnt;
del.resize(T);
while(low <= high) {
mid = (low + high) >> 1;
fill(del.begin(), del.end(), 0);
j = cnt = 0; while(pq.size()) pq.pop();
for(int i = 0; i < A; ++i) {
while(BaeW[j].fi < X[i] && j < T) pq.push(mp(S[BaeW[j].se], BaeW[j].se)), ++j;
cur = mid;
while(cur > 0 && !pq.empty()) --cur, cnt += (del[pq.top().se] = 1), pq.pop();
}
j = 0; while(pq.size()) pq.pop();
for(int i = 0; i < B; ++i) {
while(BaeS[j].fi < Y[i] && j < T) {
if(!del[BaeS[j].se]) pq.push(mp(W[BaeS[j].se], BaeS[j].se));
++j;
}
cur = mid;
while(cur > 0 && !pq.empty()) --cur, cnt += (del[pq.top().se] = 1), pq.pop();
}
if(cnt >= T) high = mid - 1;
else low = mid + 1;
}
return low <= T? low: -1;
}
//
//int A, B, T, X[M], Y[M], W[N], S[N];
//
//int main()
//{
// ios_base::sync_with_stdio(0);
// cin.tie(0), cout.tie(0);
// if(fopen("test.inp", "r")) {
// freopen("test.inp", "r", stdin);
// freopen("test.out", "w", stdout);
// }
// cin >> A >> B >> T;
// for(int i = 0; i < A; ++i) cin >> X[i];
// for(int i = 0; i < B; ++i) cin >> Y[i];
// for(int i = 0; i < T; ++i) cin >> W[i] >> S[i];
// cout << putaway(A, B, T, X, Y, W, S);
//}
Compilation message (stderr)
robots.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("O3")
# | 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... |