Submission #729679

#TimeUsernameProblemLanguageResultExecution timeMemory
729679NeroZeinRobots (IOI13_robots)C++17
28 / 100
868 ms13564 KiB
#include "robots.h"
#include <bits/stdc++.h>
using namespace std; 

bool good[1000006];

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
  if (A != 0) {
    sort(X, X + A);
  }
  if (B != 0) {
    sort(Y, Y + B); 
  }
  vector<pair<int, int>> toy(T); 
  for (int i = 0; i < T; ++i) {
    toy[i] = {W[i], S[i]};
  }
  sort(toy.begin(), toy.end()); 
  int l = 1, r = T + 1;
  while (l < r) {
    int mid = (l + r) >> 1;
    memset(good, 0, sizeof good);
    priority_queue<int> se;
    for (int i = B - 1; i >= 0 && (int) se.size() < T; --i) {
      for (int j = 0; j < mid; ++j) {
        se.push(Y[i]); 
        if ((int) se.size() == T) {
          break; 
        }
      }
    }
    for (int i = T - 1; i >= 0 && (int) se.size(); --i) {
      auto it = se.top();
      if (it > toy[i].second) {
        se.pop();
        good[i] = true; 
      }
    }
    while (se.size()) se.pop(); 
    for (int i = A - 1; i >= 0 && (int) se.size() < T; --i) {
      for (int j = 0; j < mid; ++j) { 
        se.push(X[i]);
        if ((int) se.size() == T) {
          break; 
        }
      }
    }
    for (int i = T - 1; i >= 0 && (int) se.size(); --i) {
      if (good[i]) continue; 
      auto it = se.top();  
      if (it > toy[i].first) {
        se.pop(); 
        good[i] = true; 
      }
    }
    bool ok = true; 
    for (int i = 0; i < T; ++i) {
      ok &= good[i];
    } 
    if (ok) {
      r = mid;
    } else {
      l = mid + 1; 
    }
  }
  return (l == T + 1 ? -1 : l);
}
#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...