제출 #83914

#제출 시각아이디문제언어결과실행 시간메모리
83914nikolapesic2802로봇 (IOI13_robots)C++14
100 / 100
2007 ms12852 KiB
/* - Binary search for the answer, and greedily check if we can collect all the items in the given amount of seconds. - The check can be done in T*log T so the total complexity is T*log^2 T */ #include <bits/stdc++.h> #include "robots.h" #define pb push_back using namespace std; pair<int,int> maxx=make_pair(INT_MAX,INT_MAX); int putaway(int a, int b, int t, int x[], int y[], int W[], int S[]) { sort(x,x+a); sort(y,y+b); reverse(y,y+b); vector<pair<int,int> > items(t); for(int i=0;i<t;i++) { items[i].first=W[i]; items[i].second=S[i]; } items.pb(maxx); sort(items.begin(),items.end()); int l=1,r=t+5; while(l<r) { int mid=(l+r)/2; int j=0; int test=true; priority_queue<int> s; for(int i=0;i<a;i++) { while(items[j].first<x[i]) { s.push(items[j].second); j++; } for(int k=0;k<mid;k++) { if(s.empty()) break; s.pop(); } } for(;j<t;j++) s.push(items[j].second); for(int i=0;i<b;i++) { for(int k=0;k<mid;k++) { if(s.size()==0) { break; break; } if((s.top())<y[i]) s.pop(); else { break; break; } } } if(s.size()!=0) test=false; if(test) { r=mid; } else { l=mid+1; } } if(l==t+5) return -1; return 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...