Submission #231431

#TimeUsernameProblemLanguageResultExecution timeMemory
231431quocnguyen1012Robots (IOI13_robots)C++14
100 / 100
1871 ms24456 KiB
#ifndef LOCAL
#include"robots.h"
#endif // LOCAL
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ar array

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;

const int maxn = 1e5 + 5;

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[])
{
  sort(X, X + A); sort(Y, Y + B);
  vector<ii> ve;
  for(int i = 0; i < T; ++i)
    ve.eb(W[i], S[i]);
  sort(ve.begin(), ve.end());
  auto check = [&](int mx)
  {
    priority_queue<int> pq;
    int cur = 0;
    for(int i = 0; i < A; ++i){
      while(cur < T && ve[cur].fi < X[i]){
        pq.push(ve[cur++].se);
      }
      for(int j = 0; j < mx; ++j){
        if(pq.empty()) break;
        pq.pop();
      }
    }
    for(int i = cur; i < T; ++i)
      pq.push(ve[i].se);
    for(int i = B - 1; i >= 0; --i){
      for(int j = 0; j < mx; ++j){
        if(pq.empty()) break;
        if(pq.top() >= Y[i]) return false;
        pq.pop();
      }
    }
    return pq.empty();
  };
  if(!check(T)) return -1;
  int l = 1, r = T, mid;
  while(l <= r){
    mid = (l + r) / 2;
    if(!check(mid)) l = mid + 1;
    else r = mid - 1;
  }
  return l;
}

#ifdef LOCAL
signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifdef LOCAL
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  #endif // LOCAL
  int A, B, T;
  cin >> A >> B >> T;
  int X[A], Y[B], W[T], S[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);
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...