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 "robots.h"
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <tuple>
#include <map>
#include <queue>
using namespace std;
typedef long long ll;
typedef long double ld;
#define fastInp cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
ll mx = 1e6 + 100;
int l = 0, r = T + 1;
vector<ll> svd, svd2;
for (int i = 0; i < A; i++) svd.push_back(X[i]);
for (int i = 0; i < B; i++) svd2.push_back(Y[i]);
sort(svd.rbegin(), svd.rend());
sort(svd2.rbegin(), svd2.rend());
vector<pair<int, int>> vec;
vector<tuple<int, int, int>> sved;
for (int i = 0; i < T; i++) vec.push_back({ W[i], S[i] });
sort(vec.rbegin(), vec.rend());
for (int i = 0; i < T; i++) sved.push_back({ vec[i].second, vec[i].first, i });
sort(sved.rbegin(), sved.rend());
while (r - l > 1) {
int mid = (l + r) / 2;
vector<int> skip(T, 1);
ll pt = 0, pt2 = 0;
priority_queue<pair<ll, ll>> q;
for (int i = 0; i < T; i++) {
q.push({ -get<1>(sved[i]), get<2>(sved[i]) });
if (svd2.size() > pt && svd2[pt] > get<0>(sved[i])) {
pt2++;
if (pt2 == mid) {
pt2 = 0;
pt++;
}
} else {
pair<ll, ll> qr = q.top();
q.pop();
skip[qr.second] = 0;
}
}
pt = 0, pt2 = 0;
bool f = 1;
for (int i = 0; i < T; i++) {
if (skip[i]) continue;
if (svd.size() > pt && svd[pt] > vec[i].first) {
pt2++;
if (pt2 == mid) {
pt2 = 0;
pt++;
}
} else {
f = 0;
break;
}
}
if (f) {
r = mid;
} else {
l = mid;
}
}
if (r == T + 1) {
return -1;
} else {
return r;
}
}
Compilation message (stderr)
robots.cpp: In function 'int putaway(int, int, int, int*, int*, int*, int*)':
robots.cpp:48:29: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
48 | if (svd2.size() > pt && svd2[pt] > get<0>(sved[i])) {
| ~~~~~~~~~~~~^~~~
robots.cpp:66:28: warning: comparison of integer expressions of different signedness: 'std::vector<long long int>::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
66 | if (svd.size() > pt && svd[pt] > vec[i].first) {
| ~~~~~~~~~~~^~~~
robots.cpp:19:8: warning: unused variable 'mx' [-Wunused-variable]
19 | ll mx = 1e6 + 100;
| ^~
# | 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... |