#include "prize.h"
#include <bits/stdc++.h>
using namespace std;
int find_best(int n) {
srand(time(0));
int cutoff = 0;
int lef = 0;
int ind = -1;
for(int z = 0; z < min(n,1000); z++) {
int i = rand()%n;
vector<int> res = ask(i);
if(res[0] + res[1] == 0)
return i;
if(cutoff<res[0]+res[1]) {
cutoff=res[0]+res[1];
ind=i;
lef=res[0];
}
}
while(1){
int lo = ind;
int hi = min(n-1,lo+1023);
while(lo<hi){
int mid = (lo+hi+1)/2;
vector<int>res = ask(mid);
if(res[0]+res[1]==0){
return mid;
}
if(res[0]==lef&&res[0]+res[1]==cutoff){
lo=mid;
}
else{
hi=mid-1;
}
}
ind=lo;
while(++ind<n){
vector<int>res = ask(ind);
lef=res[0];
if(res[0]+res[1]==cutoff){
break;
}
if(res[0]+res[1]==0){
return ind;
}
}
if(ind==n){
break;
}
}
return -1;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |