Submission #16494

#TimeUsernameProblemLanguageResultExecution timeMemory
16494CodingBugRobots (IOI13_robots)C++98
0 / 100
4 ms14080 KiB
#include "robots.h"
#include <queue>
#include <algorithm>
#define N 50000
#define M 1000000

using namespace std;
typedef pair<int,int> ppair;

int a[N+1],b[N+1],na,nb,m;
ppair s[M+1];

priority_queue<int> Q;
bool check(int lmt){
    int i,j,k;

    for(i=0,j=0;i<na;i++){
        for(;j<m && s[j].first<a[i];j++) Q.push(s[j].second);
        for(k=0;k<lmt && !Q.empty();k++) Q.pop();
    }
    for(;j<m;j++) Q.push(s[j].second);
    for(i=nb-1;i>=0;i--){
        for(k=0;k<lmt && !Q.empty() && Q.top()<b[i];k++) Q.pop();
    }
    return Q.empty();
}

int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
    int i;
    na=A; nb=B; m=T;
    for(i=0;i<na;i++) a[i]=X[i];
    for(i=0;i<nb;i++) b[i]=Y[i];
    for(i=0;i<m;i++) s[i]=make_pair(W[i],S[i]);

    sort(a,a+na);
    sort(b,b+nb);
    sort(s,s+m);
    int st,ed,mid;
    for(st=0,ed=T;st<ed;check(mid) ? ed=mid : st=mid+1) mid=(st+ed)/2;
    if(check(st)) return st;
    return -1;
}
#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...