# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
392800 | SavicS | Robots (IOI13_robots) | C++14 | 0 ms | 0 KiB |
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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1000005;
const int inf = 1e9 + 5;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k) print the k-th smallest number in os(0-based)
int n, m, t;
int a[50005];
int b[50005];
pii toy[maxn];
bool check(int X){
// da li mogu u X minuta
priority_queue<int> pq;
int j = 1;
ff(i,1,n){
while(j <= t && toy[j].fi < a[i]){
pq.push(toy[j].se);
j += 1;
}
// cout << "state: " << i << " " << j << endl;
// cout << "a: " << a[i] << endl;
// cout << endl;
if(pq.empty())continue;
int pomX = X;
while(!pq.empty() && pomX > 0){
pq.pop();
pomX -= 1;
}
}
while(j <= t)pq.push(toy[j++].se);
fb(i,m,1){
int pomX = X;
while(!pq.empty() && pomX > 0 && b[i] > pq.top()){
pq.pop();
pomX -= 1;
}
}
return pq.empty();
}
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]){
n = A, m = B, t = T;
ff(i,1,n)a[i] = X[i - 1];
ff(i,1,m)b[i] = Y[i - 1];
ff(i,1,T)toy[i] = {W[i - 1], S[i - 1]};
sort(a + 1, a + n + 1);
sort(b + 1, b + m + 1);
sort(toy + 1, toy + t + 1);
int l = 0, r = t + 1, ans = t + 1;
while(l <= r){
int mid = (l + r) / 2;
if(check(mid)){
r = mid - 1;
ans = mid;
}
else l = mid + 1;
}
return (ans == t + 1 ? -1 : ans);
}
//int main()
//{
// ios::sync_with_stdio(false);
// cout.tie(nullptr);
// cin.tie(nullptr);
// cin >> n >> m >> t;
// ff(i,1,n)cin >> a[i];
// ff(i,1,m)cin >> b[i];
//
// ff(i,1, t)cin >> toy[i].fi >> toy[i].se;
//
// sort(a + 1, a + n + 1);
// sort(b + 1, b + m + 1);
// sort(toy + 1, toy + t + 1);
//
// int l = 0, r = t + 1, ans = -1;
// while(l <= r){
// int mid = (l + r) / 2;
// if(check(mid)){
// r = mid - 1;
// ans = mid;
// }
// else l = mid + 1;
// }
//
// cout << ans << endl;
//
// return 0;
//}
///**
//
//3 2 4
//2 10 7
//5 10
//
//4 10
//4 5
//9 1
//8 6
//
//
//
//// probati bojenje sahovski ili slicno
//
//**/