이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "robots.h"
#include <bits/stdc++.h>
using namespace std;
typedef int INT;
//#define int long long
#define FOR(i, l, r) for(int i = (l); i < (r); i++)
#define fst first
#define snd second
#define pb push_back
#define H(x) //cout << #x << " " << x << endl;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
int A, B, T;
// weight, size
vii toys;
int *weaks, *smalls, *W, *S;
int ok(int k){
priority_queue<int> q;
int i = 0;
FOR(a, 0, A){
int w = weaks[a];
for(; i < T and W[i] < w; i++) q.push(S[i]);
H(q.size());
FOR(_, 0, k) {
if(q.empty()) break;
//cout << q.top() << endl;
q.pop();
}
}
for(; i < T; i++) q.push(S[i]);
H(q.size());
FOR(b, 0, B) {
int s = smalls[b];
FOR(_, 0, k){
if(q.empty()) break;
if(q.top() >= s) return 0;
q.pop();
}
}
return q.empty();
}
INT putaway(INT a, INT b, INT t, INT X[], INT Y[], INT w[], INT s[]) {
W = w;
S = s;
A = a; B = b; T = t;
weaks = X;
smalls = Y;
sort(weaks, weaks + A);
sort(smalls, smalls + B, greater<int>());
FOR(i, 0, T) toys.pb({W[i], S[i]});
sort(toys.begin(), toys.end());
FOR(i, 0, T) W[i] = toys[i].fst, S[i] = toys[i].snd;
toys.clear();
int lb = 0, rb = T+1;
while(lb + 1 != rb){
//cout << lb << " " << rb << endl;
int mb = (lb+rb)/2;
if(ok(mb)) rb = mb;
else lb = mb;
}
return rb == T+1 ? -1 : rb;
}
/*
1 1 2
3
3
1 4
4 1
*/
# | 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... |